docxmlater 10.2.1 → 10.2.3
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/dist/core/DocumentParser.d.ts.map +1 -1
- package/dist/core/DocumentParser.js +69 -0
- package/dist/core/DocumentParser.js.map +1 -1
- package/dist/elements/Field.d.ts.map +1 -1
- package/dist/elements/Field.js +8 -4
- package/dist/elements/Field.js.map +1 -1
- package/dist/utils/InMemoryRevisionAcceptor.d.ts.map +1 -1
- package/dist/utils/InMemoryRevisionAcceptor.js +35 -0
- package/dist/utils/InMemoryRevisionAcceptor.js.map +1 -1
- package/package.json +1 -1
- package/src/core/DocumentParser.ts +79 -1
- package/src/elements/Field.ts +12 -7
- package/src/utils/InMemoryRevisionAcceptor.ts +40 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InMemoryRevisionAcceptor.js","sourceRoot":"","sources":["../../src/utils/InMemoryRevisionAcceptor.ts"],"names":[],"mappings":";;AAuGA,sDAkEC;AAaD,0DA8PC;AA2JD,sDAWC;AAKD,8DAGC;AAKD,oDAaC;AAnmBD,qDAAkD;AAElD,mDAA8D;AAG9D,iEAAkG;AAElG,6CAA0C;AAE1C,qCAAwE;AAKxE,SAAS,SAAS;IAChB,OAAO,IAAA,2BAAkB,EAAC,IAAA,wBAAe,GAAE,EAAE,0BAA0B,CAAC,CAAC;AAC3E,CAAC;AAuCD,MAAM,sBAAsB,GAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAK1F,MAAM,uBAAuB,GAAmB;IAC9C,qBAAqB;IACrB,2BAA2B;IAC3B,uBAAuB;IACvB,gCAAgC;IAChC,0BAA0B;IAC1B,2BAA2B;IAC3B,yBAAyB;IACzB,iBAAiB;CAClB,CAAC;AAiBF,SAAgB,qBAAqB,CAAC,GAAW;IAC/C,IAAI,MAAM,GAAG,GAAG,CAAC;IAGjB,MAAM,aAAa,GAAG;QACp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MAAM;oBACR,CAAC;gBACH,CAAC;gBACD,IAAI,UAAU;oBAAE,MAAM;YACxB,CAAC;YACD,IAAI,UAAU;gBAAE,MAAM;QACxB,CAAC;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;YAEhB,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAChC,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAGD,KAAK,IAAI,CAAC,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACpD,MAAM,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,UAAU,KAAK,SAAS,IAAI,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5D,YAAY,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CAAC,8BAA8B,EAAE,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC;IAC/E,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["/**\n * InMemoryRevisionAcceptor - Accept revisions by transforming the in-memory object model\n *\n * This approach follows the industry standard (OpenXML PowerTools, Aspose.Words):\n * - Transforms Revision objects in paragraph.content[] to their \"accepted\" state\n * - For insertions: Unwrap - extract child Runs/Hyperlinks into parent paragraph\n * - For deletions: Remove - delete the revision and its content from the model\n * - For property changes: Remove the change metadata, keep the current formatting\n *\n * Unlike the raw XML approach (acceptRevisions.ts), this allows subsequent modifications\n * to the in-memory model to be correctly serialized on save().\n *\n * @see https://github.com/OfficeDev/Open-Xml-PowerTools - RevisionAccepter.cs\n * @see https://learn.microsoft.com/en-us/previous-versions/office/developer/office-2007/ee836138(v=office.12)\n */\n\nimport type { Document } from '../core/Document';\nimport { Paragraph } from '../elements/Paragraph';\nimport type { ParagraphContent } from '../elements/Paragraph';\nimport { Revision, RevisionType } from '../elements/Revision';\nimport type { Run } from '../elements/Run';\nimport type { Hyperlink } from '../elements/Hyperlink';\nimport { isRunContent, isHyperlinkContent, isImageRunContent } from '../elements/RevisionContent';\nimport type { ImageRun } from '../elements/ImageRun';\nimport { Table } from '../elements/Table';\nimport { Section } from '../elements/Section';\nimport { getGlobalLogger, createScopedLogger, ILogger } from './logger';\n\n/**\n * Get scoped logger for this module\n */\nfunction getLogger(): ILogger {\n return createScopedLogger(getGlobalLogger(), 'InMemoryRevisionAcceptor');\n}\n\n/**\n * Options for accepting revisions\n */\nexport interface AcceptRevisionsOptions {\n /** Accept insertion revisions (w:ins) - default: true */\n acceptInsertions?: boolean;\n /** Accept deletion revisions (w:del) - default: true */\n acceptDeletions?: boolean;\n /** Accept move operations (w:moveFrom, w:moveTo) - default: true */\n acceptMoves?: boolean;\n /** Accept property change revisions (rPrChange, pPrChange, etc.) - default: true */\n acceptPropertyChanges?: boolean;\n /** Remove empty tables after revision acceptance - default: true */\n cleanupEmptyTables?: boolean;\n}\n\n/**\n * Result of accepting revisions\n */\nexport interface AcceptRevisionsResult {\n /** Number of insertions accepted */\n insertionsAccepted: number;\n /** Number of deletions accepted */\n deletionsAccepted: number;\n /** Number of move operations accepted */\n movesAccepted: number;\n /** Number of property changes accepted */\n propertyChangesAccepted: number;\n /** Total revisions processed */\n totalAccepted: number;\n /** Number of empty tables removed during cleanup */\n emptyTablesRemoved: number;\n}\n\n/**\n * Revision types that represent content changes (contain actual text/runs)\n */\nconst CONTENT_REVISION_TYPES: RevisionType[] = ['insert', 'delete', 'moveFrom', 'moveTo'];\n\n/**\n * Revision types that represent property/formatting changes\n */\nconst PROPERTY_REVISION_TYPES: RevisionType[] = [\n 'runPropertiesChange',\n 'paragraphPropertiesChange',\n 'tablePropertiesChange',\n 'tableExceptionPropertiesChange',\n 'tableRowPropertiesChange',\n 'tableCellPropertiesChange',\n 'sectionPropertiesChange',\n 'numberingChange',\n];\n\n/**\n * Strip revision markup from raw XML string.\n * Used for nested tables stored as raw XML that cannot be processed via the in-memory model.\n *\n * Follows the same rules as the main revision acceptor:\n * - Insertions: Keep content, remove wrapper tags\n * - Deletions: Remove entirely (content and tags)\n * - MoveFrom: Remove entirely (source of move)\n * - MoveTo: Keep content, remove wrapper\n * - Property changes: Remove change tracking elements\n * - Range markers: Remove boundary markers\n *\n * @param xml - Raw XML string containing revision markup\n * @returns Cleaned XML with revisions accepted\n */\nexport function stripRevisionsFromXml(xml: string): string {\n let result = xml;\n\n // Step 1: Remove range markers (must be done first)\n const rangePatterns = [\n /<w:moveFromRangeStart[^>]*(?:\\/>|>.*?<\\/w:moveFromRangeStart>)/gs,\n /<w:moveFromRangeEnd[^>]*(?:\\/>|>.*?<\\/w:moveFromRangeEnd>)/gs,\n /<w:moveToRangeStart[^>]*(?:\\/>|>.*?<\\/w:moveToRangeStart>)/gs,\n /<w:moveToRangeEnd[^>]*(?:\\/>|>.*?<\\/w:moveToRangeEnd>)/gs,\n /<w:customXmlInsRangeStart[^>]*(?:\\/>|>.*?<\\/w:customXmlInsRangeStart>)/gs,\n /<w:customXmlInsRangeEnd[^>]*(?:\\/>|>.*?<\\/w:customXmlInsRangeEnd>)/gs,\n /<w:customXmlDelRangeStart[^>]*(?:\\/>|>.*?<\\/w:customXmlDelRangeStart>)/gs,\n /<w:customXmlDelRangeEnd[^>]*(?:\\/>|>.*?<\\/w:customXmlDelRangeEnd>)/gs,\n ];\n for (const pattern of rangePatterns) {\n result = result.replace(pattern, '');\n }\n\n // Step 2: Remove property change elements\n const propChangePatterns = [\n /<w:rPrChange[^>]*>[\\s\\S]*?<\\/w:rPrChange>/g,\n /<w:pPrChange[^>]*>[\\s\\S]*?<\\/w:pPrChange>/g,\n /<w:tblPrChange[^>]*>[\\s\\S]*?<\\/w:tblPrChange>/g,\n /<w:tblPrExChange[^>]*>[\\s\\S]*?<\\/w:tblPrExChange>/g,\n /<w:tcPrChange[^>]*>[\\s\\S]*?<\\/w:tcPrChange>/g,\n /<w:trPrChange[^>]*>[\\s\\S]*?<\\/w:trPrChange>/g,\n /<w:sectPrChange[^>]*>[\\s\\S]*?<\\/w:sectPrChange>/g,\n /<w:tblGridChange[^>]*>[\\s\\S]*?<\\/w:tblGridChange>/g,\n /<w:numberingChange[^>]*>[\\s\\S]*?<\\/w:numberingChange>/g,\n ];\n for (const pattern of propChangePatterns) {\n result = result.replace(pattern, '');\n }\n\n // Step 3: Remove deletions entirely (including content)\n // Iterate until no more deletions (handles nested cases)\n let prevLen = 0;\n while (result.length !== prevLen) {\n prevLen = result.length;\n result = result.replace(/<w:del\\b[^>]*>[\\s\\S]*?<\\/w:del>/g, '');\n }\n result = result.replace(/<w:del\\b[^>]*\\/>/g, '');\n\n // Step 4: Remove moveFrom entirely (source of moved content)\n prevLen = 0;\n while (result.length !== prevLen) {\n prevLen = result.length;\n result = result.replace(/<w:moveFrom\\b[^>]*>[\\s\\S]*?<\\/w:moveFrom>/g, '');\n }\n result = result.replace(/<w:moveFrom\\b[^>]*\\/>/g, '');\n\n // Step 5: Unwrap moveTo (keep content, remove wrapper)\n result = result.replace(/<\\/w:moveTo>/g, '');\n result = result.replace(/<w:moveTo\\b[^>]*>/g, '');\n\n // Step 6: Unwrap insertions (keep content, remove wrapper)\n result = result.replace(/<\\/w:ins>/g, '');\n result = result.replace(/<w:ins\\b[^>]*>/g, '');\n\n // Step 7: Clean up orphaned tags\n result = result.replace(/<w:ins\\b[^>]*\\/>/g, '');\n result = result.replace(/<w:del\\b[^>]*\\/>/g, '');\n result = result.replace(/<w:moveFrom\\b[^>]*\\/>/g, '');\n result = result.replace(/<w:moveTo\\b[^>]*\\/>/g, '');\n\n return result;\n}\n\n/**\n * Accept all revisions in the document by transforming the in-memory model.\n *\n * This is the industry-standard approach used by OpenXML PowerTools, Aspose.Words,\n * and other production DOCX libraries. It allows subsequent modifications to the\n * document to work correctly.\n *\n * @param doc - Document to process\n * @param options - Options for which revision types to accept\n * @returns Result with counts of accepted revisions\n */\nexport function acceptRevisionsInMemory(\n doc: Document,\n options: AcceptRevisionsOptions = {}\n): AcceptRevisionsResult {\n const logger = getLogger();\n const opts: Required<AcceptRevisionsOptions> = {\n acceptInsertions: options.acceptInsertions ?? true,\n acceptDeletions: options.acceptDeletions ?? true,\n acceptMoves: options.acceptMoves ?? true,\n acceptPropertyChanges: options.acceptPropertyChanges ?? true,\n cleanupEmptyTables: options.cleanupEmptyTables ?? true,\n };\n\n const result: AcceptRevisionsResult = {\n insertionsAccepted: 0,\n deletionsAccepted: 0,\n movesAccepted: 0,\n propertyChangesAccepted: 0,\n totalAccepted: 0,\n emptyTablesRemoved: 0,\n };\n\n logger.info('Accepting revisions in-memory', { options: opts });\n\n // Validate move pairs before accepting if moves are being accepted\n // Orphaned moves could result in content loss (moveFrom without moveTo = content deleted)\n if (opts.acceptMoves) {\n const revisionManager = doc.getRevisionManager();\n if (revisionManager) {\n const movePairValidation = revisionManager.validateMovePairs();\n if (!movePairValidation.valid) {\n if (movePairValidation.orphanedMoveFrom.length > 0) {\n logger.warn(\n 'Orphaned moveFrom revisions detected - accepting these will DELETE content permanently ' +\n '(content was moved from here but no moveTo destination exists)',\n { orphanedMoveIds: movePairValidation.orphanedMoveFrom }\n );\n }\n if (movePairValidation.orphanedMoveTo.length > 0) {\n logger.warn(\n 'Orphaned moveTo revisions detected - content may be duplicated ' +\n '(content moved to here but no moveFrom source exists)',\n { orphanedMoveIds: movePairValidation.orphanedMoveTo }\n );\n }\n }\n }\n }\n\n // Process all paragraphs in the document body\n const paragraphs = doc.getAllParagraphs();\n for (const paragraph of paragraphs) {\n const paragraphResult = acceptRevisionsInParagraph(paragraph, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n }\n\n // Process paragraphs in tables and clear table/row/cell property changes\n const tables = doc.getTables();\n for (const table of tables) {\n // Clear tblPrChange on table\n if (opts.acceptPropertyChanges && table.getTblPrChange()) {\n table.clearTblPrChange();\n result.propertyChangesAccepted++;\n }\n\n for (const row of table.getRows()) {\n // Clear trPrChange on row\n if (opts.acceptPropertyChanges && row.getTrPrChange()) {\n row.clearTrPrChange();\n result.propertyChangesAccepted++;\n }\n\n for (const cell of row.getCells()) {\n // Clear tcPrChange on cell\n if (opts.acceptPropertyChanges && cell.getTcPrChange()) {\n cell.clearTcPrChange();\n result.propertyChangesAccepted++;\n }\n\n // Clear cell structural revision markers (cellIns/cellDel/cellMerge)\n if (opts.acceptPropertyChanges && cell.getCellRevision()) {\n cell.clearCellRevision();\n result.propertyChangesAccepted++;\n }\n\n // Process paragraphs in the cell\n for (const paragraph of cell.getParagraphs()) {\n const paragraphResult = acceptRevisionsInParagraph(paragraph, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n }\n\n // Process raw nested content (nested tables stored as XML)\n // These cannot be processed via the in-memory model, so we use XML-based stripping\n if (cell.hasRawNestedContent()) {\n const rawContent = cell.getRawNestedContent();\n for (let i = 0; i < rawContent.length; i++) {\n const item = rawContent[i];\n if (item) {\n const cleanedXml = stripRevisionsFromXml(item.xml);\n if (cleanedXml !== item.xml) {\n cell.updateRawNestedContent(i, cleanedXml);\n // Count revisions stripped from nested content\n // We can't distinguish types in raw XML, so count as property changes\n result.propertyChangesAccepted++;\n logger.debug('Stripped revisions from nested content', {\n type: item.type,\n position: item.position,\n originalLength: item.xml.length,\n cleanedLength: cleanedXml.length,\n });\n }\n }\n }\n }\n }\n }\n }\n\n // Process paragraphs in headers\n const headerFooterManager = doc.getHeaderFooterManager();\n if (headerFooterManager) {\n const headers = headerFooterManager.getAllHeaders();\n for (const headerEntry of headers) {\n const elements = headerEntry.header.getElements();\n for (const element of elements) {\n // Element can be Paragraph or Table - use instanceof for type safety\n if (element instanceof Paragraph) {\n const paragraphResult = acceptRevisionsInParagraph(element, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n } else if (element instanceof Table) {\n // It's a Table - process its cells\n for (const row of element.getRows()) {\n for (const cell of row.getCells()) {\n for (const paragraph of cell.getParagraphs()) {\n const paragraphResult = acceptRevisionsInParagraph(paragraph, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n }\n // Process raw nested content in header tables\n if (cell.hasRawNestedContent()) {\n const rawContent = cell.getRawNestedContent();\n for (let i = 0; i < rawContent.length; i++) {\n const item = rawContent[i];\n if (item) {\n const cleanedXml = stripRevisionsFromXml(item.xml);\n if (cleanedXml !== item.xml) {\n cell.updateRawNestedContent(i, cleanedXml);\n result.propertyChangesAccepted++;\n }\n }\n }\n }\n }\n }\n }\n }\n }\n\n // Process paragraphs in footers\n const footers = headerFooterManager.getAllFooters();\n for (const footerEntry of footers) {\n const elements = footerEntry.footer.getElements();\n for (const element of elements) {\n // Element can be Paragraph or Table - use instanceof for type safety\n if (element instanceof Paragraph) {\n const paragraphResult = acceptRevisionsInParagraph(element, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n } else if (element instanceof Table) {\n // It's a Table - process its cells\n for (const row of element.getRows()) {\n for (const cell of row.getCells()) {\n for (const paragraph of cell.getParagraphs()) {\n const paragraphResult = acceptRevisionsInParagraph(paragraph, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n }\n // Process raw nested content in footer tables\n if (cell.hasRawNestedContent()) {\n const rawContent = cell.getRawNestedContent();\n for (let i = 0; i < rawContent.length; i++) {\n const item = rawContent[i];\n if (item) {\n const cleanedXml = stripRevisionsFromXml(item.xml);\n if (cleanedXml !== item.xml) {\n cell.updateRawNestedContent(i, cleanedXml);\n result.propertyChangesAccepted++;\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n\n // Clear sectPrChange on document section\n if (opts.acceptPropertyChanges) {\n const section = doc.getSection();\n if (section?.getSectPrChange()) {\n section.clearSectPrChange();\n result.propertyChangesAccepted++;\n }\n }\n\n // Clear revision manager\n const revisionManager = doc.getRevisionManager();\n if (revisionManager) {\n revisionManager.clear();\n }\n\n // Disable track changes setting\n doc.disableTrackChanges();\n\n // Cleanup empty tables if enabled\n // This removes tables that have no visible content after revision acceptance\n // (e.g., tables where all content was deleted via tracked changes)\n if (opts.cleanupEmptyTables) {\n result.emptyTablesRemoved = cleanupEmptyTables(doc, logger);\n }\n\n result.totalAccepted =\n result.insertionsAccepted +\n result.deletionsAccepted +\n result.movesAccepted +\n result.propertyChangesAccepted;\n\n logger.info('Revisions accepted in-memory', {\n insertions: result.insertionsAccepted,\n deletions: result.deletionsAccepted,\n moves: result.movesAccepted,\n propertyChanges: result.propertyChangesAccepted,\n total: result.totalAccepted,\n emptyTablesRemoved: result.emptyTablesRemoved,\n });\n\n return result;\n}\n\n/**\n * Accept revisions in a single paragraph by transforming its content array.\n *\n * The transformation follows these rules:\n * - Insertions (w:ins): Unwrap - extract child content into parent position\n * - Deletions (w:del): Remove - delete revision and its content\n * - MoveFrom (w:moveFrom): Remove - content exists at moveTo destination\n * - MoveTo (w:moveTo): Unwrap - keep content, remove wrapper\n * - Property changes: Remove from model (current formatting is kept)\n *\n * @param paragraph - Paragraph to process\n * @param options - Options for which revision types to accept\n * @returns Result with counts of accepted revisions\n */\nfunction acceptRevisionsInParagraph(\n paragraph: Paragraph,\n options: Required<AcceptRevisionsOptions>\n): AcceptRevisionsResult {\n const result: AcceptRevisionsResult = {\n insertionsAccepted: 0,\n deletionsAccepted: 0,\n movesAccepted: 0,\n propertyChangesAccepted: 0,\n totalAccepted: 0,\n emptyTablesRemoved: 0,\n };\n\n const content = paragraph.getContent();\n const newContent: ParagraphContent[] = [];\n\n for (const item of content) {\n if (item instanceof Revision) {\n const revisionType = item.getType();\n\n // Handle insertion revisions (w:ins)\n if (revisionType === 'insert' && options.acceptInsertions) {\n // Unwrap: Extract child content into parent position\n const childContent = item.getContent();\n for (const child of childContent) {\n // Check ImageRun FIRST since ImageRun extends Run\n if (isImageRunContent(child)) {\n newContent.push(child);\n } else if (isRunContent(child)) {\n newContent.push(child);\n } else if (isHyperlinkContent(child)) {\n newContent.push(child);\n }\n }\n result.insertionsAccepted++;\n continue;\n }\n\n // Handle deletion revisions (w:del)\n if (revisionType === 'delete' && options.acceptDeletions) {\n // Remove: Don't add to newContent - content is deleted\n result.deletionsAccepted++;\n continue;\n }\n\n // Handle moveFrom revisions (source of moved content)\n if (revisionType === 'moveFrom' && options.acceptMoves) {\n // Remove: Content exists at moveTo destination\n result.movesAccepted++;\n continue;\n }\n\n // Handle moveTo revisions (destination of moved content)\n if (revisionType === 'moveTo' && options.acceptMoves) {\n // Unwrap: Keep content, remove wrapper\n const childContent = item.getContent();\n for (const child of childContent) {\n // Check ImageRun FIRST since ImageRun extends Run\n if (isImageRunContent(child)) {\n newContent.push(child);\n } else if (isRunContent(child)) {\n newContent.push(child);\n } else if (isHyperlinkContent(child)) {\n newContent.push(child);\n }\n }\n result.movesAccepted++;\n continue;\n }\n\n // Handle property change revisions\n if (PROPERTY_REVISION_TYPES.includes(revisionType) && options.acceptPropertyChanges) {\n // For property changes, the revision is metadata attached to runs\n // The current formatting (newProperties) is already applied to the run\n // We just need to remove the change tracking metadata\n // The content inside should be preserved\n const childContent = item.getContent();\n for (const child of childContent) {\n // Check ImageRun FIRST since ImageRun extends Run\n if (isImageRunContent(child)) {\n newContent.push(child);\n } else if (isRunContent(child)) {\n newContent.push(child);\n } else if (isHyperlinkContent(child)) {\n newContent.push(child);\n }\n }\n result.propertyChangesAccepted++;\n continue;\n }\n\n // If we reach here, this revision type is not being accepted\n // Keep it in the content\n newContent.push(item);\n } else {\n // Non-revision content - keep as-is\n newContent.push(item);\n }\n }\n\n // Replace paragraph content with the transformed content\n paragraph.setContent(newContent);\n\n // Clear paragraph property change tracking (pPrChange) if accepting property changes\n // This removes the w:pPrChange element from the paragraph's formatting\n if (options.acceptPropertyChanges) {\n const formatting = paragraph.getFormatting();\n if (formatting.pPrChange) {\n paragraph.clearParagraphPropertiesChange();\n result.propertyChangesAccepted++;\n }\n }\n\n // Clear paragraph mark deletion tracking if accepting deletions\n // This removes the w:del element from w:pPr/w:rPr\n if (options.acceptDeletions) {\n const formatting = paragraph.getFormatting();\n if (formatting.paragraphMarkDeletion) {\n paragraph.clearParagraphMarkDeletion();\n result.deletionsAccepted++;\n }\n }\n\n // Clear paragraph mark insertion tracking if accepting insertions\n // This removes the w:ins element from w:pPr/w:rPr\n if (options.acceptInsertions) {\n const formatting = paragraph.getFormatting();\n if (formatting.paragraphMarkInsertion) {\n paragraph.clearParagraphMarkInsertion();\n result.insertionsAccepted++;\n }\n }\n\n return result;\n}\n\n/**\n * Check if a paragraph has any revisions\n */\nexport function paragraphHasRevisions(paragraph: Paragraph): boolean {\n const content = paragraph.getContent();\n if (content.some((item) => item instanceof Revision)) {\n return true;\n }\n // Also check paragraph mark revision markers in w:pPr/w:rPr\n const formatting = paragraph.getFormatting();\n if (formatting.paragraphMarkDeletion || formatting.paragraphMarkInsertion) {\n return true;\n }\n return false;\n}\n\n/**\n * Get all revisions from a paragraph\n */\nexport function getRevisionsFromParagraph(paragraph: Paragraph): Revision[] {\n const content = paragraph.getContent();\n return content.filter((item): item is Revision => item instanceof Revision);\n}\n\n/**\n * Count revisions by type in a document\n */\nexport function countRevisionsByType(doc: Document): Map<RevisionType, number> {\n const counts = new Map<RevisionType, number>();\n\n const paragraphs = doc.getAllParagraphs();\n for (const paragraph of paragraphs) {\n const revisions = getRevisionsFromParagraph(paragraph);\n for (const revision of revisions) {\n const type = revision.getType();\n counts.set(type, (counts.get(type) || 0) + 1);\n }\n }\n\n return counts;\n}\n\n/**\n * Remove tables that have no visible content after revision acceptance.\n *\n * A table is considered empty if ALL cells in ALL rows have no text content.\n * This handles cases where all table content was deleted via tracked changes -\n * the deletion markers are stripped but the empty table structure remains.\n *\n * @param doc - Document to clean up\n * @param logger - Logger instance for debug output\n * @returns Number of empty tables removed\n */\nfunction cleanupEmptyTables(doc: Document, logger: ILogger): number {\n const tables = doc.getTables();\n let removedCount = 0;\n const tablesToRemove: number[] = [];\n\n for (let tableIndex = 0; tableIndex < tables.length; tableIndex++) {\n const table = tables[tableIndex];\n if (!table) continue;\n\n let hasContent = false;\n const rows = table.getRows();\n\n for (const row of rows) {\n const cells = row.getCells();\n for (const cell of cells) {\n const paragraphs = cell.getParagraphs();\n for (const para of paragraphs) {\n const text = para.getText().trim();\n if (text.length > 0) {\n hasContent = true;\n break;\n }\n }\n if (hasContent) break;\n }\n if (hasContent) break;\n }\n\n if (!hasContent) {\n // Mark this table for removal (store index)\n tablesToRemove.push(tableIndex);\n logger.debug('Found empty table for removal', { tableIndex });\n }\n }\n\n // Remove tables in reverse order to preserve indices\n for (let i = tablesToRemove.length - 1; i >= 0; i--) {\n const tableIndex = tablesToRemove[i];\n if (tableIndex !== undefined && doc.removeTable(tableIndex)) {\n removedCount++;\n logger.debug('Removed empty table', { tableIndex });\n }\n }\n\n if (removedCount > 0) {\n logger.info('Empty table cleanup complete', { tablesRemoved: removedCount });\n }\n\n return removedCount;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"InMemoryRevisionAcceptor.js","sourceRoot":"","sources":["../../src/utils/InMemoryRevisionAcceptor.ts"],"names":[],"mappings":";;AAwGA,sDAkEC;AAaD,0DA8PC;AAkMD,sDAWC;AAKD,8DAGC;AAKD,oDAaC;AA3oBD,qDAAkD;AAElD,mDAA8D;AAG9D,iEAAkG;AAElG,6CAAiD;AACjD,6CAA0C;AAE1C,qCAAwE;AAKxE,SAAS,SAAS;IAChB,OAAO,IAAA,2BAAkB,EAAC,IAAA,wBAAe,GAAE,EAAE,0BAA0B,CAAC,CAAC;AAC3E,CAAC;AAuCD,MAAM,sBAAsB,GAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAK1F,MAAM,uBAAuB,GAAmB;IAC9C,qBAAqB;IACrB,2BAA2B;IAC3B,uBAAuB;IACvB,gCAAgC;IAChC,0BAA0B;IAC1B,2BAA2B;IAC3B,yBAAyB;IACzB,iBAAiB;CAClB,CAAC;AAiBF,SAAgB,qBAAqB,CAAC,GAAW;IAC/C,IAAI,MAAM,GAAG,GAAG,CAAC;IAGjB,MAAM,aAAa,GAAG;QACpB,kEAAkE;QAClE,8DAA8D;QAC9D,8DAA8D;QAC9D,0DAA0D;QAC1D,0EAA0E;QAC1E,sEAAsE;QACtE,0EAA0E;QAC1E,sEAAsE;KACvE,CAAC;IACF,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;QACpC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACvC,CAAC;IAGD,MAAM,kBAAkB,GAAG;QACzB,4CAA4C;QAC5C,4CAA4C;QAC5C,gDAAgD;QAChD,oDAAoD;QACpD,8CAA8C;QAC9C,8CAA8C;QAC9C,kDAAkD;QAClD,oDAAoD;QACpD,wDAAwD;KACzD,CAAC;IACF,KAAK,MAAM,OAAO,IAAI,kBAAkB,EA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E,CAAC;IACH,CAAC;IAGD,KAAK,IAAI,CAAC,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACpD,MAAM,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,UAAU,KAAK,SAAS,IAAI,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5D,YAAY,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CAAC,8BAA8B,EAAE,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC;IAC/E,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["/**\n * InMemoryRevisionAcceptor - Accept revisions by transforming the in-memory object model\n *\n * This approach follows the industry standard (OpenXML PowerTools, Aspose.Words):\n * - Transforms Revision objects in paragraph.content[] to their \"accepted\" state\n * - For insertions: Unwrap - extract child Runs/Hyperlinks into parent paragraph\n * - For deletions: Remove - delete the revision and its content from the model\n * - For property changes: Remove the change metadata, keep the current formatting\n *\n * Unlike the raw XML approach (acceptRevisions.ts), this allows subsequent modifications\n * to the in-memory model to be correctly serialized on save().\n *\n * @see https://github.com/OfficeDev/Open-Xml-PowerTools - RevisionAccepter.cs\n * @see https://learn.microsoft.com/en-us/previous-versions/office/developer/office-2007/ee836138(v=office.12)\n */\n\nimport type { Document } from '../core/Document';\nimport { Paragraph } from '../elements/Paragraph';\nimport type { ParagraphContent } from '../elements/Paragraph';\nimport { Revision, RevisionType } from '../elements/Revision';\nimport type { Run } from '../elements/Run';\nimport type { Hyperlink } from '../elements/Hyperlink';\nimport { isRunContent, isHyperlinkContent, isImageRunContent } from '../elements/RevisionContent';\nimport type { ImageRun } from '../elements/ImageRun';\nimport { ComplexField } from '../elements/Field';\nimport { Table } from '../elements/Table';\nimport { Section } from '../elements/Section';\nimport { getGlobalLogger, createScopedLogger, ILogger } from './logger';\n\n/**\n * Get scoped logger for this module\n */\nfunction getLogger(): ILogger {\n return createScopedLogger(getGlobalLogger(), 'InMemoryRevisionAcceptor');\n}\n\n/**\n * Options for accepting revisions\n */\nexport interface AcceptRevisionsOptions {\n /** Accept insertion revisions (w:ins) - default: true */\n acceptInsertions?: boolean;\n /** Accept deletion revisions (w:del) - default: true */\n acceptDeletions?: boolean;\n /** Accept move operations (w:moveFrom, w:moveTo) - default: true */\n acceptMoves?: boolean;\n /** Accept property change revisions (rPrChange, pPrChange, etc.) - default: true */\n acceptPropertyChanges?: boolean;\n /** Remove empty tables after revision acceptance - default: true */\n cleanupEmptyTables?: boolean;\n}\n\n/**\n * Result of accepting revisions\n */\nexport interface AcceptRevisionsResult {\n /** Number of insertions accepted */\n insertionsAccepted: number;\n /** Number of deletions accepted */\n deletionsAccepted: number;\n /** Number of move operations accepted */\n movesAccepted: number;\n /** Number of property changes accepted */\n propertyChangesAccepted: number;\n /** Total revisions processed */\n totalAccepted: number;\n /** Number of empty tables removed during cleanup */\n emptyTablesRemoved: number;\n}\n\n/**\n * Revision types that represent content changes (contain actual text/runs)\n */\nconst CONTENT_REVISION_TYPES: RevisionType[] = ['insert', 'delete', 'moveFrom', 'moveTo'];\n\n/**\n * Revision types that represent property/formatting changes\n */\nconst PROPERTY_REVISION_TYPES: RevisionType[] = [\n 'runPropertiesChange',\n 'paragraphPropertiesChange',\n 'tablePropertiesChange',\n 'tableExceptionPropertiesChange',\n 'tableRowPropertiesChange',\n 'tableCellPropertiesChange',\n 'sectionPropertiesChange',\n 'numberingChange',\n];\n\n/**\n * Strip revision markup from raw XML string.\n * Used for nested tables stored as raw XML that cannot be processed via the in-memory model.\n *\n * Follows the same rules as the main revision acceptor:\n * - Insertions: Keep content, remove wrapper tags\n * - Deletions: Remove entirely (content and tags)\n * - MoveFrom: Remove entirely (source of move)\n * - MoveTo: Keep content, remove wrapper\n * - Property changes: Remove change tracking elements\n * - Range markers: Remove boundary markers\n *\n * @param xml - Raw XML string containing revision markup\n * @returns Cleaned XML with revisions accepted\n */\nexport function stripRevisionsFromXml(xml: string): string {\n let result = xml;\n\n // Step 1: Remove range markers (must be done first)\n const rangePatterns = [\n /<w:moveFromRangeStart[^>]*(?:\\/>|>.*?<\\/w:moveFromRangeStart>)/gs,\n /<w:moveFromRangeEnd[^>]*(?:\\/>|>.*?<\\/w:moveFromRangeEnd>)/gs,\n /<w:moveToRangeStart[^>]*(?:\\/>|>.*?<\\/w:moveToRangeStart>)/gs,\n /<w:moveToRangeEnd[^>]*(?:\\/>|>.*?<\\/w:moveToRangeEnd>)/gs,\n /<w:customXmlInsRangeStart[^>]*(?:\\/>|>.*?<\\/w:customXmlInsRangeStart>)/gs,\n /<w:customXmlInsRangeEnd[^>]*(?:\\/>|>.*?<\\/w:customXmlInsRangeEnd>)/gs,\n /<w:customXmlDelRangeStart[^>]*(?:\\/>|>.*?<\\/w:customXmlDelRangeStart>)/gs,\n /<w:customXmlDelRangeEnd[^>]*(?:\\/>|>.*?<\\/w:customXmlDelRangeEnd>)/gs,\n ];\n for (const pattern of rangePatterns) {\n result = result.replace(pattern, '');\n }\n\n // Step 2: Remove property change elements\n const propChangePatterns = [\n /<w:rPrChange[^>]*>[\\s\\S]*?<\\/w:rPrChange>/g,\n /<w:pPrChange[^>]*>[\\s\\S]*?<\\/w:pPrChange>/g,\n /<w:tblPrChange[^>]*>[\\s\\S]*?<\\/w:tblPrChange>/g,\n /<w:tblPrExChange[^>]*>[\\s\\S]*?<\\/w:tblPrExChange>/g,\n /<w:tcPrChange[^>]*>[\\s\\S]*?<\\/w:tcPrChange>/g,\n /<w:trPrChange[^>]*>[\\s\\S]*?<\\/w:trPrChange>/g,\n /<w:sectPrChange[^>]*>[\\s\\S]*?<\\/w:sectPrChange>/g,\n /<w:tblGridChange[^>]*>[\\s\\S]*?<\\/w:tblGridChange>/g,\n /<w:numberingChange[^>]*>[\\s\\S]*?<\\/w:numberingChange>/g,\n ];\n for (const pattern of propChangePatterns) {\n result = result.replace(pattern, '');\n }\n\n // Step 3: Remove deletions entirely (including content)\n // Iterate until no more deletions (handles nested cases)\n let prevLen = 0;\n while (result.length !== prevLen) {\n prevLen = result.length;\n result = result.replace(/<w:del\\b[^>]*>[\\s\\S]*?<\\/w:del>/g, '');\n }\n result = result.replace(/<w:del\\b[^>]*\\/>/g, '');\n\n // Step 4: Remove moveFrom entirely (source of moved content)\n prevLen = 0;\n while (result.length !== prevLen) {\n prevLen = result.length;\n result = result.replace(/<w:moveFrom\\b[^>]*>[\\s\\S]*?<\\/w:moveFrom>/g, '');\n }\n result = result.replace(/<w:moveFrom\\b[^>]*\\/>/g, '');\n\n // Step 5: Unwrap moveTo (keep content, remove wrapper)\n result = result.replace(/<\\/w:moveTo>/g, '');\n result = result.replace(/<w:moveTo\\b[^>]*>/g, '');\n\n // Step 6: Unwrap insertions (keep content, remove wrapper)\n result = result.replace(/<\\/w:ins>/g, '');\n result = result.replace(/<w:ins\\b[^>]*>/g, '');\n\n // Step 7: Clean up orphaned tags\n result = result.replace(/<w:ins\\b[^>]*\\/>/g, '');\n result = result.replace(/<w:del\\b[^>]*\\/>/g, '');\n result = result.replace(/<w:moveFrom\\b[^>]*\\/>/g, '');\n result = result.replace(/<w:moveTo\\b[^>]*\\/>/g, '');\n\n return result;\n}\n\n/**\n * Accept all revisions in the document by transforming the in-memory model.\n *\n * This is the industry-standard approach used by OpenXML PowerTools, Aspose.Words,\n * and other production DOCX libraries. It allows subsequent modifications to the\n * document to work correctly.\n *\n * @param doc - Document to process\n * @param options - Options for which revision types to accept\n * @returns Result with counts of accepted revisions\n */\nexport function acceptRevisionsInMemory(\n doc: Document,\n options: AcceptRevisionsOptions = {}\n): AcceptRevisionsResult {\n const logger = getLogger();\n const opts: Required<AcceptRevisionsOptions> = {\n acceptInsertions: options.acceptInsertions ?? true,\n acceptDeletions: options.acceptDeletions ?? true,\n acceptMoves: options.acceptMoves ?? true,\n acceptPropertyChanges: options.acceptPropertyChanges ?? true,\n cleanupEmptyTables: options.cleanupEmptyTables ?? true,\n };\n\n const result: AcceptRevisionsResult = {\n insertionsAccepted: 0,\n deletionsAccepted: 0,\n movesAccepted: 0,\n propertyChangesAccepted: 0,\n totalAccepted: 0,\n emptyTablesRemoved: 0,\n };\n\n logger.info('Accepting revisions in-memory', { options: opts });\n\n // Validate move pairs before accepting if moves are being accepted\n // Orphaned moves could result in content loss (moveFrom without moveTo = content deleted)\n if (opts.acceptMoves) {\n const revisionManager = doc.getRevisionManager();\n if (revisionManager) {\n const movePairValidation = revisionManager.validateMovePairs();\n if (!movePairValidation.valid) {\n if (movePairValidation.orphanedMoveFrom.length > 0) {\n logger.warn(\n 'Orphaned moveFrom revisions detected - accepting these will DELETE content permanently ' +\n '(content was moved from here but no moveTo destination exists)',\n { orphanedMoveIds: movePairValidation.orphanedMoveFrom }\n );\n }\n if (movePairValidation.orphanedMoveTo.length > 0) {\n logger.warn(\n 'Orphaned moveTo revisions detected - content may be duplicated ' +\n '(content moved to here but no moveFrom source exists)',\n { orphanedMoveIds: movePairValidation.orphanedMoveTo }\n );\n }\n }\n }\n }\n\n // Process all paragraphs in the document body\n const paragraphs = doc.getAllParagraphs();\n for (const paragraph of paragraphs) {\n const paragraphResult = acceptRevisionsInParagraph(paragraph, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n }\n\n // Process paragraphs in tables and clear table/row/cell property changes\n const tables = doc.getTables();\n for (const table of tables) {\n // Clear tblPrChange on table\n if (opts.acceptPropertyChanges && table.getTblPrChange()) {\n table.clearTblPrChange();\n result.propertyChangesAccepted++;\n }\n\n for (const row of table.getRows()) {\n // Clear trPrChange on row\n if (opts.acceptPropertyChanges && row.getTrPrChange()) {\n row.clearTrPrChange();\n result.propertyChangesAccepted++;\n }\n\n for (const cell of row.getCells()) {\n // Clear tcPrChange on cell\n if (opts.acceptPropertyChanges && cell.getTcPrChange()) {\n cell.clearTcPrChange();\n result.propertyChangesAccepted++;\n }\n\n // Clear cell structural revision markers (cellIns/cellDel/cellMerge)\n if (opts.acceptPropertyChanges && cell.getCellRevision()) {\n cell.clearCellRevision();\n result.propertyChangesAccepted++;\n }\n\n // Process paragraphs in the cell\n for (const paragraph of cell.getParagraphs()) {\n const paragraphResult = acceptRevisionsInParagraph(paragraph, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n }\n\n // Process raw nested content (nested tables stored as XML)\n // These cannot be processed via the in-memory model, so we use XML-based stripping\n if (cell.hasRawNestedContent()) {\n const rawContent = cell.getRawNestedContent();\n for (let i = 0; i < rawContent.length; i++) {\n const item = rawContent[i];\n if (item) {\n const cleanedXml = stripRevisionsFromXml(item.xml);\n if (cleanedXml !== item.xml) {\n cell.updateRawNestedContent(i, cleanedXml);\n // Count revisions stripped from nested content\n // We can't distinguish types in raw XML, so count as property changes\n result.propertyChangesAccepted++;\n logger.debug('Stripped revisions from nested content', {\n type: item.type,\n position: item.position,\n originalLength: item.xml.length,\n cleanedLength: cleanedXml.length,\n });\n }\n }\n }\n }\n }\n }\n }\n\n // Process paragraphs in headers\n const headerFooterManager = doc.getHeaderFooterManager();\n if (headerFooterManager) {\n const headers = headerFooterManager.getAllHeaders();\n for (const headerEntry of headers) {\n const elements = headerEntry.header.getElements();\n for (const element of elements) {\n // Element can be Paragraph or Table - use instanceof for type safety\n if (element instanceof Paragraph) {\n const paragraphResult = acceptRevisionsInParagraph(element, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n } else if (element instanceof Table) {\n // It's a Table - process its cells\n for (const row of element.getRows()) {\n for (const cell of row.getCells()) {\n for (const paragraph of cell.getParagraphs()) {\n const paragraphResult = acceptRevisionsInParagraph(paragraph, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n }\n // Process raw nested content in header tables\n if (cell.hasRawNestedContent()) {\n const rawContent = cell.getRawNestedContent();\n for (let i = 0; i < rawContent.length; i++) {\n const item = rawContent[i];\n if (item) {\n const cleanedXml = stripRevisionsFromXml(item.xml);\n if (cleanedXml !== item.xml) {\n cell.updateRawNestedContent(i, cleanedXml);\n result.propertyChangesAccepted++;\n }\n }\n }\n }\n }\n }\n }\n }\n }\n\n // Process paragraphs in footers\n const footers = headerFooterManager.getAllFooters();\n for (const footerEntry of footers) {\n const elements = footerEntry.footer.getElements();\n for (const element of elements) {\n // Element can be Paragraph or Table - use instanceof for type safety\n if (element instanceof Paragraph) {\n const paragraphResult = acceptRevisionsInParagraph(element, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n } else if (element instanceof Table) {\n // It's a Table - process its cells\n for (const row of element.getRows()) {\n for (const cell of row.getCells()) {\n for (const paragraph of cell.getParagraphs()) {\n const paragraphResult = acceptRevisionsInParagraph(paragraph, opts);\n result.insertionsAccepted += paragraphResult.insertionsAccepted;\n result.deletionsAccepted += paragraphResult.deletionsAccepted;\n result.movesAccepted += paragraphResult.movesAccepted;\n result.propertyChangesAccepted += paragraphResult.propertyChangesAccepted;\n }\n // Process raw nested content in footer tables\n if (cell.hasRawNestedContent()) {\n const rawContent = cell.getRawNestedContent();\n for (let i = 0; i < rawContent.length; i++) {\n const item = rawContent[i];\n if (item) {\n const cleanedXml = stripRevisionsFromXml(item.xml);\n if (cleanedXml !== item.xml) {\n cell.updateRawNestedContent(i, cleanedXml);\n result.propertyChangesAccepted++;\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n\n // Clear sectPrChange on document section\n if (opts.acceptPropertyChanges) {\n const section = doc.getSection();\n if (section?.getSectPrChange()) {\n section.clearSectPrChange();\n result.propertyChangesAccepted++;\n }\n }\n\n // Clear revision manager\n const revisionManager = doc.getRevisionManager();\n if (revisionManager) {\n revisionManager.clear();\n }\n\n // Disable track changes setting\n doc.disableTrackChanges();\n\n // Cleanup empty tables if enabled\n // This removes tables that have no visible content after revision acceptance\n // (e.g., tables where all content was deleted via tracked changes)\n if (opts.cleanupEmptyTables) {\n result.emptyTablesRemoved = cleanupEmptyTables(doc, logger);\n }\n\n result.totalAccepted =\n result.insertionsAccepted +\n result.deletionsAccepted +\n result.movesAccepted +\n result.propertyChangesAccepted;\n\n logger.info('Revisions accepted in-memory', {\n insertions: result.insertionsAccepted,\n deletions: result.deletionsAccepted,\n moves: result.movesAccepted,\n propertyChanges: result.propertyChangesAccepted,\n total: result.totalAccepted,\n emptyTablesRemoved: result.emptyTablesRemoved,\n });\n\n return result;\n}\n\n/**\n * Accept revisions in a single paragraph by transforming its content array.\n *\n * The transformation follows these rules:\n * - Insertions (w:ins): Unwrap - extract child content into parent position\n * - Deletions (w:del): Remove - delete revision and its content\n * - MoveFrom (w:moveFrom): Remove - content exists at moveTo destination\n * - MoveTo (w:moveTo): Unwrap - keep content, remove wrapper\n * - Property changes: Remove from model (current formatting is kept)\n *\n * @param paragraph - Paragraph to process\n * @param options - Options for which revision types to accept\n * @returns Result with counts of accepted revisions\n */\nfunction acceptRevisionsInParagraph(\n paragraph: Paragraph,\n options: Required<AcceptRevisionsOptions>\n): AcceptRevisionsResult {\n const result: AcceptRevisionsResult = {\n insertionsAccepted: 0,\n deletionsAccepted: 0,\n movesAccepted: 0,\n propertyChangesAccepted: 0,\n totalAccepted: 0,\n emptyTablesRemoved: 0,\n };\n\n const content = paragraph.getContent();\n const newContent: ParagraphContent[] = [];\n\n for (const item of content) {\n if (item instanceof Revision) {\n const revisionType = item.getType();\n\n // Handle insertion revisions (w:ins)\n if (revisionType === 'insert' && options.acceptInsertions) {\n // Unwrap: Extract child content into parent position\n const childContent = item.getContent();\n for (const child of childContent) {\n // Check ImageRun FIRST since ImageRun extends Run\n if (isImageRunContent(child)) {\n newContent.push(child);\n } else if (isRunContent(child)) {\n newContent.push(child);\n } else if (isHyperlinkContent(child)) {\n newContent.push(child);\n }\n }\n result.insertionsAccepted++;\n continue;\n }\n\n // Handle deletion revisions (w:del)\n if (revisionType === 'delete' && options.acceptDeletions) {\n // Remove: Don't add to newContent - content is deleted\n result.deletionsAccepted++;\n continue;\n }\n\n // Handle moveFrom revisions (source of moved content)\n if (revisionType === 'moveFrom' && options.acceptMoves) {\n // Remove: Content exists at moveTo destination\n result.movesAccepted++;\n continue;\n }\n\n // Handle moveTo revisions (destination of moved content)\n if (revisionType === 'moveTo' && options.acceptMoves) {\n // Unwrap: Keep content, remove wrapper\n const childContent = item.getContent();\n for (const child of childContent) {\n // Check ImageRun FIRST since ImageRun extends Run\n if (isImageRunContent(child)) {\n newContent.push(child);\n } else if (isRunContent(child)) {\n newContent.push(child);\n } else if (isHyperlinkContent(child)) {\n newContent.push(child);\n }\n }\n result.movesAccepted++;\n continue;\n }\n\n // Handle property change revisions\n if (PROPERTY_REVISION_TYPES.includes(revisionType) && options.acceptPropertyChanges) {\n // For property changes, the revision is metadata attached to runs\n // The current formatting (newProperties) is already applied to the run\n // We just need to remove the change tracking metadata\n // The content inside should be preserved\n const childContent = item.getContent();\n for (const child of childContent) {\n // Check ImageRun FIRST since ImageRun extends Run\n if (isImageRunContent(child)) {\n newContent.push(child);\n } else if (isRunContent(child)) {\n newContent.push(child);\n } else if (isHyperlinkContent(child)) {\n newContent.push(child);\n }\n }\n result.propertyChangesAccepted++;\n continue;\n }\n\n // If we reach here, this revision type is not being accepted\n // Keep it in the content\n newContent.push(item);\n } else if (item instanceof ComplexField && item.hasResultRevisions()) {\n // Accept revisions nested inside ComplexField result sections\n // Merge insertion/moveTo text into the result before clearing\n const fieldRevisions = item.getResultRevisions();\n let mergedResult = item.getResult() || '';\n const revisionsToKeep: Revision[] = [];\n\n for (const rev of fieldRevisions) {\n const revType = rev.getType();\n if (revType === 'insert' && options.acceptInsertions) {\n // Merge insertion text into result\n for (const child of rev.getRuns()) {\n mergedResult += child.getText() || '';\n }\n result.insertionsAccepted++;\n } else if (revType === 'delete' && options.acceptDeletions) {\n // Deleted text was never in result — just count it\n result.deletionsAccepted++;\n } else if (revType === 'moveTo' && options.acceptMoves) {\n // Merge moveTo text into result\n for (const child of rev.getRuns()) {\n mergedResult += child.getText() || '';\n }\n result.movesAccepted++;\n } else if (revType === 'moveFrom' && options.acceptMoves) {\n result.movesAccepted++;\n } else {\n // Revision type not being accepted — keep it\n revisionsToKeep.push(rev);\n }\n }\n\n // setResult() clears both resultRevisions and resultContent\n item.setResult(mergedResult);\n // Restore any unaccepted revisions\n if (revisionsToKeep.length > 0) {\n item.setResultRevisions(revisionsToKeep);\n }\n newContent.push(item);\n } else {\n // Non-revision content - keep as-is\n newContent.push(item);\n }\n }\n\n // Replace paragraph content with the transformed content\n paragraph.setContent(newContent);\n\n // Clear paragraph property change tracking (pPrChange) if accepting property changes\n // This removes the w:pPrChange element from the paragraph's formatting\n if (options.acceptPropertyChanges) {\n const formatting = paragraph.getFormatting();\n if (formatting.pPrChange) {\n paragraph.clearParagraphPropertiesChange();\n result.propertyChangesAccepted++;\n }\n }\n\n // Clear paragraph mark deletion tracking if accepting deletions\n // This removes the w:del element from w:pPr/w:rPr\n if (options.acceptDeletions) {\n const formatting = paragraph.getFormatting();\n if (formatting.paragraphMarkDeletion) {\n paragraph.clearParagraphMarkDeletion();\n result.deletionsAccepted++;\n }\n }\n\n // Clear paragraph mark insertion tracking if accepting insertions\n // This removes the w:ins element from w:pPr/w:rPr\n if (options.acceptInsertions) {\n const formatting = paragraph.getFormatting();\n if (formatting.paragraphMarkInsertion) {\n paragraph.clearParagraphMarkInsertion();\n result.insertionsAccepted++;\n }\n }\n\n return result;\n}\n\n/**\n * Check if a paragraph has any revisions\n */\nexport function paragraphHasRevisions(paragraph: Paragraph): boolean {\n const content = paragraph.getContent();\n if (content.some((item) => item instanceof Revision)) {\n return true;\n }\n // Also check paragraph mark revision markers in w:pPr/w:rPr\n const formatting = paragraph.getFormatting();\n if (formatting.paragraphMarkDeletion || formatting.paragraphMarkInsertion) {\n return true;\n }\n return false;\n}\n\n/**\n * Get all revisions from a paragraph\n */\nexport function getRevisionsFromParagraph(paragraph: Paragraph): Revision[] {\n const content = paragraph.getContent();\n return content.filter((item): item is Revision => item instanceof Revision);\n}\n\n/**\n * Count revisions by type in a document\n */\nexport function countRevisionsByType(doc: Document): Map<RevisionType, number> {\n const counts = new Map<RevisionType, number>();\n\n const paragraphs = doc.getAllParagraphs();\n for (const paragraph of paragraphs) {\n const revisions = getRevisionsFromParagraph(paragraph);\n for (const revision of revisions) {\n const type = revision.getType();\n counts.set(type, (counts.get(type) || 0) + 1);\n }\n }\n\n return counts;\n}\n\n/**\n * Remove tables that have no visible content after revision acceptance.\n *\n * A table is considered empty if ALL cells in ALL rows have no text content.\n * This handles cases where all table content was deleted via tracked changes -\n * the deletion markers are stripped but the empty table structure remains.\n *\n * @param doc - Document to clean up\n * @param logger - Logger instance for debug output\n * @returns Number of empty tables removed\n */\nfunction cleanupEmptyTables(doc: Document, logger: ILogger): number {\n const tables = doc.getTables();\n let removedCount = 0;\n const tablesToRemove: number[] = [];\n\n for (let tableIndex = 0; tableIndex < tables.length; tableIndex++) {\n const table = tables[tableIndex];\n if (!table) continue;\n\n let hasContent = false;\n const rows = table.getRows();\n\n for (const row of rows) {\n const cells = row.getCells();\n for (const cell of cells) {\n const paragraphs = cell.getParagraphs();\n for (const para of paragraphs) {\n const text = para.getText().trim();\n if (text.length > 0) {\n hasContent = true;\n break;\n }\n }\n if (hasContent) break;\n }\n if (hasContent) break;\n }\n\n if (!hasContent) {\n // Mark this table for removal (store index)\n tablesToRemove.push(tableIndex);\n logger.debug('Found empty table for removal', { tableIndex });\n }\n }\n\n // Remove tables in reverse order to preserve indices\n for (let i = tablesToRemove.length - 1; i >= 0; i--) {\n const tableIndex = tablesToRemove[i];\n if (tableIndex !== undefined && doc.removeTable(tableIndex)) {\n removedCount++;\n logger.debug('Removed empty table', { tableIndex });\n }\n }\n\n if (removedCount > 0) {\n logger.info('Empty table cleanup complete', { tablesRemoved: removedCount });\n }\n\n return removedCount;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -2689,6 +2689,7 @@ export class DocumentParser {
|
|
|
2689
2689
|
let fieldRuns: Run[] = [];
|
|
2690
2690
|
let fieldRevisions: Revision[] = []; // Track revisions inside field result section
|
|
2691
2691
|
let instructionRevisions: Revision[] = []; // Track revisions in instruction area
|
|
2692
|
+
let orderedResultItems: Array<Run | Revision> = []; // Track interleaved order of result runs + revisions
|
|
2692
2693
|
let fieldState: 'begin' | 'instruction' | 'separate' | 'result' | 'end' | null = null;
|
|
2693
2694
|
let nestingDepth = 0;
|
|
2694
2695
|
let hasNestedFields = false;
|
|
@@ -2749,6 +2750,7 @@ export class DocumentParser {
|
|
|
2749
2750
|
fieldRuns = [];
|
|
2750
2751
|
instructionRevisions = [];
|
|
2751
2752
|
fieldRevisions = [];
|
|
2753
|
+
orderedResultItems = [];
|
|
2752
2754
|
fieldState = null;
|
|
2753
2755
|
hasNestedFields = false;
|
|
2754
2756
|
fieldStartIndex = -1;
|
|
@@ -2801,6 +2803,7 @@ export class DocumentParser {
|
|
|
2801
2803
|
fieldRuns = [];
|
|
2802
2804
|
instructionRevisions = [];
|
|
2803
2805
|
fieldRevisions = [];
|
|
2806
|
+
orderedResultItems = [];
|
|
2804
2807
|
fieldState = null;
|
|
2805
2808
|
break;
|
|
2806
2809
|
}
|
|
@@ -2834,6 +2837,69 @@ export class DocumentParser {
|
|
|
2834
2837
|
if (isHyperlinkInstruction(instruction)) {
|
|
2835
2838
|
const parsed = parseHyperlinkInstruction(instruction);
|
|
2836
2839
|
if (parsed && resultText) {
|
|
2840
|
+
// HYPERLINK fields with tracked changes in the result region cannot be
|
|
2841
|
+
// converted to Hyperlink objects — the revisions would become orphaned
|
|
2842
|
+
// standalone paragraph content. Keep as ComplexField instead.
|
|
2843
|
+
if (fieldRevisions.length > 0) {
|
|
2844
|
+
const complexField = this.createComplexFieldFromRuns(fieldRuns);
|
|
2845
|
+
if (complexField) {
|
|
2846
|
+
// Build ordered resultContent for correct round-trip serialization
|
|
2847
|
+
if (orderedResultItems.length > 0) {
|
|
2848
|
+
const orderedContent: XMLElement[] = [];
|
|
2849
|
+
for (const resultItem of orderedResultItems) {
|
|
2850
|
+
if (resultItem instanceof Run) {
|
|
2851
|
+
orderedContent.push(resultItem.toXML());
|
|
2852
|
+
} else if (resultItem instanceof Revision) {
|
|
2853
|
+
const xml = resultItem.toXML();
|
|
2854
|
+
if (xml) orderedContent.push(xml);
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
// Compute accepted text (non-revision runs + insertion text)
|
|
2858
|
+
let acceptedText = '';
|
|
2859
|
+
for (const resultItem of orderedResultItems) {
|
|
2860
|
+
if (resultItem instanceof Run) {
|
|
2861
|
+
acceptedText += resultItem.getText() || '';
|
|
2862
|
+
} else if (
|
|
2863
|
+
resultItem instanceof Revision &&
|
|
2864
|
+
resultItem.getType() === 'insert'
|
|
2865
|
+
) {
|
|
2866
|
+
for (const child of resultItem.getRuns()) {
|
|
2867
|
+
acceptedText += child.getText() || '';
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
// Set accepted text as the result (for getResult() API)
|
|
2872
|
+
complexField.setResult(acceptedText || complexField.getResult() || '');
|
|
2873
|
+
// Add ordered content for serialization (overrides the text-based path)
|
|
2874
|
+
for (const xmlEl of orderedContent) {
|
|
2875
|
+
complexField.addResultContent(xmlEl);
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
// Attach revisions for tracking/acceptance
|
|
2879
|
+
for (const rev of fieldRevisions) {
|
|
2880
|
+
rev.setFieldContext({
|
|
2881
|
+
field: complexField,
|
|
2882
|
+
instruction: complexField.getInstruction(),
|
|
2883
|
+
position: 'result',
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
complexField.setResultRevisions(fieldRevisions);
|
|
2887
|
+
groupedContent.push(complexField);
|
|
2888
|
+
} else {
|
|
2889
|
+
fieldRuns.forEach((run) => groupedContent.push(run));
|
|
2890
|
+
for (const revision of fieldRevisions) {
|
|
2891
|
+
groupedContent.push(revision);
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
fieldRuns = [];
|
|
2895
|
+
instructionRevisions = [];
|
|
2896
|
+
fieldRevisions = [];
|
|
2897
|
+
orderedResultItems = [];
|
|
2898
|
+
fieldState = null;
|
|
2899
|
+
break;
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
// Normal path (no revisions) — convert to Hyperlink object
|
|
2837
2903
|
let hyperlink: Hyperlink;
|
|
2838
2904
|
if (parsed.url && parsed.url.trim() !== '') {
|
|
2839
2905
|
// External hyperlink (or combined external + anchor)
|
|
@@ -2876,6 +2942,7 @@ export class DocumentParser {
|
|
|
2876
2942
|
fieldRuns = [];
|
|
2877
2943
|
instructionRevisions = [];
|
|
2878
2944
|
fieldRevisions = [];
|
|
2945
|
+
orderedResultItems = [];
|
|
2879
2946
|
fieldState = null;
|
|
2880
2947
|
break;
|
|
2881
2948
|
}
|
|
@@ -2895,6 +2962,7 @@ export class DocumentParser {
|
|
|
2895
2962
|
fieldRuns = [];
|
|
2896
2963
|
instructionRevisions = [];
|
|
2897
2964
|
fieldRevisions = [];
|
|
2965
|
+
orderedResultItems = [];
|
|
2898
2966
|
fieldState = null;
|
|
2899
2967
|
break;
|
|
2900
2968
|
}
|
|
@@ -2929,6 +2997,7 @@ export class DocumentParser {
|
|
|
2929
2997
|
fieldRuns = [];
|
|
2930
2998
|
instructionRevisions = [];
|
|
2931
2999
|
fieldRevisions = [];
|
|
3000
|
+
orderedResultItems = [];
|
|
2932
3001
|
fieldState = null;
|
|
2933
3002
|
}
|
|
2934
3003
|
break;
|
|
@@ -2942,11 +3011,16 @@ export class DocumentParser {
|
|
|
2942
3011
|
} else {
|
|
2943
3012
|
// Regular run - check if we're inside a field result section
|
|
2944
3013
|
if (nestingDepth > 0) {
|
|
2945
|
-
// Inside a
|
|
3014
|
+
// Inside a field - collect all runs to preserve raw structure
|
|
2946
3015
|
fieldRuns.push(item);
|
|
3016
|
+
// Track result runs for interleaved ordering (only outer field level)
|
|
3017
|
+
if (nestingDepth === 1 && (fieldState === 'separate' || fieldState === 'result')) {
|
|
3018
|
+
orderedResultItems.push(item);
|
|
3019
|
+
}
|
|
2947
3020
|
} else if (fieldState === 'separate' || fieldState === 'result') {
|
|
2948
3021
|
// This run is part of the field result - collect it
|
|
2949
3022
|
fieldRuns.push(item);
|
|
3023
|
+
orderedResultItems.push(item);
|
|
2950
3024
|
fieldState = 'result';
|
|
2951
3025
|
} else if (fieldState === 'begin' || fieldState === 'instruction') {
|
|
2952
3026
|
// We're in the middle of parsing field instruction
|
|
@@ -2965,6 +3039,7 @@ export class DocumentParser {
|
|
|
2965
3039
|
fieldRuns = [];
|
|
2966
3040
|
instructionRevisions = [];
|
|
2967
3041
|
fieldRevisions = [];
|
|
3042
|
+
orderedResultItems = [];
|
|
2968
3043
|
fieldState = null;
|
|
2969
3044
|
groupedContent.push(item);
|
|
2970
3045
|
} else {
|
|
@@ -2981,6 +3056,7 @@ export class DocumentParser {
|
|
|
2981
3056
|
// Set preliminary field context (field reference will be set when ComplexField is created)
|
|
2982
3057
|
item.setFieldContext({ position: 'result' });
|
|
2983
3058
|
fieldRevisions.push(item);
|
|
3059
|
+
orderedResultItems.push(item);
|
|
2984
3060
|
fieldState = 'result';
|
|
2985
3061
|
defaultLogger.debug(
|
|
2986
3062
|
`Found revision inside complex field result: type=${item.getType()}, id=${item.getId()}`
|
|
@@ -3009,6 +3085,7 @@ export class DocumentParser {
|
|
|
3009
3085
|
fieldRuns = [];
|
|
3010
3086
|
instructionRevisions = [];
|
|
3011
3087
|
fieldRevisions = [];
|
|
3088
|
+
orderedResultItems = [];
|
|
3012
3089
|
fieldState = null;
|
|
3013
3090
|
groupedContent.push(item);
|
|
3014
3091
|
} else {
|
|
@@ -3032,6 +3109,7 @@ export class DocumentParser {
|
|
|
3032
3109
|
fieldRuns = [];
|
|
3033
3110
|
instructionRevisions = [];
|
|
3034
3111
|
fieldRevisions = [];
|
|
3112
|
+
orderedResultItems = [];
|
|
3035
3113
|
fieldState = null;
|
|
3036
3114
|
}
|
|
3037
3115
|
groupedContent.push(item);
|
package/src/elements/Field.ts
CHANGED
|
@@ -685,6 +685,8 @@ export class ComplexField {
|
|
|
685
685
|
*/
|
|
686
686
|
setResult(result: string): this {
|
|
687
687
|
this.result = result;
|
|
688
|
+
this.resultRevisions = []; // Clear orphaned revisions from old text
|
|
689
|
+
this.resultContent = []; // Clear raw XML content since we have new text
|
|
688
690
|
return this;
|
|
689
691
|
}
|
|
690
692
|
|
|
@@ -968,13 +970,16 @@ export class ComplexField {
|
|
|
968
970
|
});
|
|
969
971
|
}
|
|
970
972
|
|
|
971
|
-
// 4a. Result revisions
|
|
972
|
-
//
|
|
973
|
-
//
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
973
|
+
// 4a. Result revisions — only when NOT using resultContent
|
|
974
|
+
// When resultContent is populated (e.g., by DocumentParser with interleaved revision XML),
|
|
975
|
+
// it already includes revision elements in the correct interleaved position.
|
|
976
|
+
// Emitting them again here would cause duplication.
|
|
977
|
+
if (this.resultContent.length === 0) {
|
|
978
|
+
for (const revision of this.resultRevisions) {
|
|
979
|
+
const revisionXml = revision.toXML();
|
|
980
|
+
if (revisionXml) {
|
|
981
|
+
runs.push(revisionXml);
|
|
982
|
+
}
|
|
978
983
|
}
|
|
979
984
|
}
|
|
980
985
|
|
|
@@ -22,6 +22,7 @@ import type { Run } from '../elements/Run';
|
|
|
22
22
|
import type { Hyperlink } from '../elements/Hyperlink';
|
|
23
23
|
import { isRunContent, isHyperlinkContent, isImageRunContent } from '../elements/RevisionContent';
|
|
24
24
|
import type { ImageRun } from '../elements/ImageRun';
|
|
25
|
+
import { ComplexField } from '../elements/Field';
|
|
25
26
|
import { Table } from '../elements/Table';
|
|
26
27
|
import { Section } from '../elements/Section';
|
|
27
28
|
import { getGlobalLogger, createScopedLogger, ILogger } from './logger';
|
|
@@ -544,6 +545,45 @@ function acceptRevisionsInParagraph(
|
|
|
544
545
|
// If we reach here, this revision type is not being accepted
|
|
545
546
|
// Keep it in the content
|
|
546
547
|
newContent.push(item);
|
|
548
|
+
} else if (item instanceof ComplexField && item.hasResultRevisions()) {
|
|
549
|
+
// Accept revisions nested inside ComplexField result sections
|
|
550
|
+
// Merge insertion/moveTo text into the result before clearing
|
|
551
|
+
const fieldRevisions = item.getResultRevisions();
|
|
552
|
+
let mergedResult = item.getResult() || '';
|
|
553
|
+
const revisionsToKeep: Revision[] = [];
|
|
554
|
+
|
|
555
|
+
for (const rev of fieldRevisions) {
|
|
556
|
+
const revType = rev.getType();
|
|
557
|
+
if (revType === 'insert' && options.acceptInsertions) {
|
|
558
|
+
// Merge insertion text into result
|
|
559
|
+
for (const child of rev.getRuns()) {
|
|
560
|
+
mergedResult += child.getText() || '';
|
|
561
|
+
}
|
|
562
|
+
result.insertionsAccepted++;
|
|
563
|
+
} else if (revType === 'delete' && options.acceptDeletions) {
|
|
564
|
+
// Deleted text was never in result — just count it
|
|
565
|
+
result.deletionsAccepted++;
|
|
566
|
+
} else if (revType === 'moveTo' && options.acceptMoves) {
|
|
567
|
+
// Merge moveTo text into result
|
|
568
|
+
for (const child of rev.getRuns()) {
|
|
569
|
+
mergedResult += child.getText() || '';
|
|
570
|
+
}
|
|
571
|
+
result.movesAccepted++;
|
|
572
|
+
} else if (revType === 'moveFrom' && options.acceptMoves) {
|
|
573
|
+
result.movesAccepted++;
|
|
574
|
+
} else {
|
|
575
|
+
// Revision type not being accepted — keep it
|
|
576
|
+
revisionsToKeep.push(rev);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// setResult() clears both resultRevisions and resultContent
|
|
581
|
+
item.setResult(mergedResult);
|
|
582
|
+
// Restore any unaccepted revisions
|
|
583
|
+
if (revisionsToKeep.length > 0) {
|
|
584
|
+
item.setResultRevisions(revisionsToKeep);
|
|
585
|
+
}
|
|
586
|
+
newContent.push(item);
|
|
547
587
|
} else {
|
|
548
588
|
// Non-revision content - keep as-is
|
|
549
589
|
newContent.push(item);
|