docxmlater 10.0.2 → 10.0.4
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/README.md +3 -2
- package/dist/constants/legacyCompatFlags.d.ts.map +1 -1
- package/dist/constants/legacyCompatFlags.js.map +1 -1
- package/dist/constants/limits.d.ts +0 -27
- package/dist/constants/limits.d.ts.map +1 -1
- package/dist/constants/limits.js +13 -13
- package/dist/constants/limits.js.map +1 -1
- package/dist/core/Document.d.ts +23 -19
- package/dist/core/Document.d.ts.map +1 -1
- package/dist/core/Document.js +197 -63
- package/dist/core/Document.js.map +1 -1
- package/dist/core/DocumentContent.d.ts.map +1 -1
- package/dist/core/DocumentContent.js.map +1 -1
- package/dist/core/DocumentGenerator.d.ts.map +1 -1
- package/dist/core/DocumentGenerator.js +59 -24
- package/dist/core/DocumentGenerator.js.map +1 -1
- package/dist/core/DocumentIdManager.d.ts.map +1 -1
- package/dist/core/DocumentIdManager.js.map +1 -1
- package/dist/core/DocumentParser.d.ts +6 -6
- package/dist/core/DocumentParser.d.ts.map +1 -1
- package/dist/core/DocumentParser.js +86 -55
- package/dist/core/DocumentParser.js.map +1 -1
- package/dist/core/DocumentValidator.d.ts.map +1 -1
- package/dist/core/DocumentValidator.js.map +1 -1
- package/dist/core/Relationship.d.ts.map +1 -1
- package/dist/core/Relationship.js +1 -1
- package/dist/core/Relationship.js.map +1 -1
- package/dist/core/RelationshipManager.js +3 -3
- package/dist/core/RelationshipManager.js.map +1 -1
- package/dist/elements/AlternateContent.js.map +1 -1
- package/dist/elements/Bookmark.d.ts.map +1 -1
- package/dist/elements/Bookmark.js.map +1 -1
- package/dist/elements/BookmarkManager.d.ts.map +1 -1
- package/dist/elements/BookmarkManager.js.map +1 -1
- package/dist/elements/Comment.js +1 -1
- package/dist/elements/Comment.js.map +1 -1
- package/dist/elements/CommentManager.d.ts.map +1 -1
- package/dist/elements/CommentManager.js +8 -2
- package/dist/elements/CommentManager.js.map +1 -1
- package/dist/elements/CommonTypes.d.ts.map +1 -1
- package/dist/elements/CommonTypes.js +1 -2
- package/dist/elements/CommonTypes.js.map +1 -1
- package/dist/elements/CustomXml.js.map +1 -1
- package/dist/elements/Endnote.d.ts.map +1 -1
- package/dist/elements/Endnote.js.map +1 -1
- package/dist/elements/EndnoteManager.d.ts.map +1 -1
- package/dist/elements/EndnoteManager.js.map +1 -1
- package/dist/elements/Field.d.ts.map +1 -1
- package/dist/elements/Field.js +31 -28
- package/dist/elements/Field.js.map +1 -1
- package/dist/elements/FieldHelpers.d.ts.map +1 -1
- package/dist/elements/FieldHelpers.js +6 -6
- package/dist/elements/FieldHelpers.js.map +1 -1
- package/dist/elements/FontManager.d.ts.map +1 -1
- package/dist/elements/FontManager.js.map +1 -1
- package/dist/elements/Footer.js.map +1 -1
- package/dist/elements/Footnote.d.ts.map +1 -1
- package/dist/elements/Footnote.js.map +1 -1
- package/dist/elements/FootnoteManager.d.ts.map +1 -1
- package/dist/elements/FootnoteManager.js.map +1 -1
- package/dist/elements/Header.js.map +1 -1
- package/dist/elements/HeaderFooterManager.js.map +1 -1
- package/dist/elements/Hyperlink.d.ts.map +1 -1
- package/dist/elements/Hyperlink.js +5 -5
- package/dist/elements/Hyperlink.js.map +1 -1
- package/dist/elements/Image.d.ts +2 -2
- package/dist/elements/Image.d.ts.map +1 -1
- package/dist/elements/Image.js +21 -5
- package/dist/elements/Image.js.map +1 -1
- package/dist/elements/ImageManager.d.ts.map +1 -1
- package/dist/elements/ImageManager.js +2 -2
- package/dist/elements/ImageManager.js.map +1 -1
- package/dist/elements/ImageRun.js.map +1 -1
- package/dist/elements/MathElement.js.map +1 -1
- package/dist/elements/Paragraph.d.ts +8 -0
- package/dist/elements/Paragraph.d.ts.map +1 -1
- package/dist/elements/Paragraph.js +153 -118
- package/dist/elements/Paragraph.js.map +1 -1
- package/dist/elements/PreservedElement.js.map +1 -1
- package/dist/elements/PropertyChangeTypes.js.map +1 -1
- package/dist/elements/RangeMarker.js.map +1 -1
- package/dist/elements/Revision.d.ts +1 -0
- package/dist/elements/Revision.d.ts.map +1 -1
- package/dist/elements/Revision.js +44 -5
- package/dist/elements/Revision.js.map +1 -1
- package/dist/elements/RevisionContent.js.map +1 -1
- package/dist/elements/RevisionManager.d.ts.map +1 -1
- package/dist/elements/RevisionManager.js.map +1 -1
- package/dist/elements/Run.d.ts.map +1 -1
- package/dist/elements/Run.js +1 -3
- package/dist/elements/Run.js.map +1 -1
- package/dist/elements/Section.d.ts.map +1 -1
- package/dist/elements/Section.js +127 -118
- package/dist/elements/Section.js.map +1 -1
- package/dist/elements/Shape.d.ts.map +1 -1
- package/dist/elements/Shape.js +21 -0
- package/dist/elements/Shape.js.map +1 -1
- package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
- package/dist/elements/StructuredDocumentTag.js +20 -8
- package/dist/elements/StructuredDocumentTag.js.map +1 -1
- package/dist/elements/Table.d.ts +2 -2
- package/dist/elements/Table.d.ts.map +1 -1
- package/dist/elements/Table.js +29 -35
- package/dist/elements/Table.js.map +1 -1
- package/dist/elements/TableCell.d.ts +2 -2
- package/dist/elements/TableCell.d.ts.map +1 -1
- package/dist/elements/TableCell.js +63 -67
- package/dist/elements/TableCell.js.map +1 -1
- package/dist/elements/TableGridChange.js.map +1 -1
- package/dist/elements/TableOfContents.d.ts +6 -6
- package/dist/elements/TableOfContents.d.ts.map +1 -1
- package/dist/elements/TableOfContents.js.map +1 -1
- package/dist/elements/TableOfContentsElement.js.map +1 -1
- package/dist/elements/TableRow.d.ts.map +1 -1
- package/dist/elements/TableRow.js +65 -47
- package/dist/elements/TableRow.js.map +1 -1
- package/dist/elements/TextBox.d.ts.map +1 -1
- package/dist/elements/TextBox.js +1 -1
- package/dist/elements/TextBox.js.map +1 -1
- package/dist/formatting/AbstractNumbering.d.ts +1 -1
- package/dist/formatting/AbstractNumbering.d.ts.map +1 -1
- package/dist/formatting/AbstractNumbering.js +11 -11
- package/dist/formatting/AbstractNumbering.js.map +1 -1
- package/dist/formatting/NumberingInstance.d.ts.map +1 -1
- package/dist/formatting/NumberingInstance.js +4 -4
- package/dist/formatting/NumberingInstance.js.map +1 -1
- package/dist/formatting/NumberingLevel.d.ts.map +1 -1
- package/dist/formatting/NumberingLevel.js +26 -26
- package/dist/formatting/NumberingLevel.js.map +1 -1
- package/dist/formatting/NumberingManager.d.ts +1 -1
- package/dist/formatting/NumberingManager.d.ts.map +1 -1
- package/dist/formatting/NumberingManager.js.map +1 -1
- package/dist/formatting/Style.d.ts.map +1 -1
- package/dist/formatting/Style.js +87 -95
- package/dist/formatting/Style.js.map +1 -1
- package/dist/formatting/StylesManager.d.ts +3 -3
- package/dist/formatting/StylesManager.d.ts.map +1 -1
- package/dist/formatting/StylesManager.js.map +1 -1
- package/dist/helpers/CleanupHelper.js.map +1 -1
- package/dist/images/ImageOptimizer.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/managers/DrawingManager.d.ts.map +1 -1
- package/dist/managers/DrawingManager.js.map +1 -1
- package/dist/tracking/DocumentTrackingContext.js.map +1 -1
- package/dist/tracking/TrackingContext.js.map +1 -1
- package/dist/types/compatibility-types.js.map +1 -1
- package/dist/types/formatting.js.map +1 -1
- package/dist/types/list-types.d.ts +4 -4
- package/dist/types/list-types.d.ts.map +1 -1
- package/dist/types/list-types.js.map +1 -1
- package/dist/types/settings-types.js.map +1 -1
- package/dist/types/styleConfig.js.map +1 -1
- package/dist/utils/ChangelogGenerator.d.ts.map +1 -1
- package/dist/utils/ChangelogGenerator.js.map +1 -1
- package/dist/utils/CompatibilityUpgrader.d.ts.map +1 -1
- package/dist/utils/CompatibilityUpgrader.js +7 -7
- package/dist/utils/CompatibilityUpgrader.js.map +1 -1
- package/dist/utils/InMemoryRevisionAcceptor.d.ts.map +1 -1
- package/dist/utils/InMemoryRevisionAcceptor.js +23 -2
- package/dist/utils/InMemoryRevisionAcceptor.js.map +1 -1
- package/dist/utils/MoveOperationHelper.js.map +1 -1
- package/dist/utils/RevisionAwareProcessor.js.map +1 -1
- package/dist/utils/RevisionWalker.js.map +1 -1
- package/dist/utils/SelectiveRevisionAcceptor.d.ts +1 -0
- package/dist/utils/SelectiveRevisionAcceptor.d.ts.map +1 -1
- package/dist/utils/SelectiveRevisionAcceptor.js +46 -0
- package/dist/utils/SelectiveRevisionAcceptor.js.map +1 -1
- package/dist/utils/ShadingResolver.js +1 -1
- package/dist/utils/ShadingResolver.js.map +1 -1
- package/dist/utils/acceptRevisions.d.ts +0 -28
- package/dist/utils/acceptRevisions.d.ts.map +1 -1
- package/dist/utils/acceptRevisions.js +5 -7
- package/dist/utils/acceptRevisions.js.map +1 -1
- package/dist/utils/cnfStyleDecoder.js +1 -1
- package/dist/utils/cnfStyleDecoder.js.map +1 -1
- package/dist/utils/corruptionDetection.js.map +1 -1
- package/dist/utils/dateFormatting.js.map +1 -1
- package/dist/utils/deepClone.d.ts +0 -1
- package/dist/utils/deepClone.d.ts.map +1 -1
- package/dist/utils/deepClone.js +0 -7
- package/dist/utils/deepClone.js.map +1 -1
- package/dist/utils/diagnostics.d.ts +2 -2
- package/dist/utils/diagnostics.d.ts.map +1 -1
- package/dist/utils/diagnostics.js.map +1 -1
- package/dist/utils/errorHandling.js.map +1 -1
- package/dist/utils/formatting.js.map +1 -1
- package/dist/utils/list-detection.d.ts +2 -2
- package/dist/utils/list-detection.d.ts.map +1 -1
- package/dist/utils/list-detection.js +3 -3
- package/dist/utils/list-detection.js.map +1 -1
- package/dist/utils/logger.d.ts +2 -4
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +0 -2
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/parsingHelpers.js.map +1 -1
- package/dist/utils/stripTrackedChanges.d.ts +0 -19
- package/dist/utils/stripTrackedChanges.d.ts.map +1 -1
- package/dist/utils/stripTrackedChanges.js +0 -2
- package/dist/utils/stripTrackedChanges.js.map +1 -1
- package/dist/utils/textDiff.js.map +1 -1
- package/dist/utils/units.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/xmlSanitization.js.map +1 -1
- package/dist/validation/RevisionAutoFixer.js.map +1 -1
- package/dist/validation/RevisionValidator.js.map +1 -1
- package/dist/validation/ValidationRules.js.map +1 -1
- package/dist/validation/index.js.map +1 -1
- package/dist/xml/XMLBuilder.d.ts.map +1 -1
- package/dist/xml/XMLBuilder.js +10 -0
- package/dist/xml/XMLBuilder.js.map +1 -1
- package/dist/xml/XMLParser.d.ts.map +1 -1
- package/dist/xml/XMLParser.js +4 -5
- package/dist/xml/XMLParser.js.map +1 -1
- package/dist/zip/ZipHandler.js.map +1 -1
- package/dist/zip/ZipReader.js.map +1 -1
- package/dist/zip/ZipWriter.js.map +1 -1
- package/dist/zip/errors.js.map +1 -1
- package/dist/zip/types.js.map +1 -1
- package/package.json +34 -4
- package/src/__tests__/helper-methods.test.ts +512 -0
- package/src/constants/legacyCompatFlags.ts +138 -0
- package/src/constants/limits.ts +50 -0
- package/src/core/CLAUDE.md +109 -0
- package/src/core/Document.ts +15569 -0
- package/src/core/DocumentContent.ts +467 -0
- package/src/core/DocumentGenerator.ts +1104 -0
- package/src/core/DocumentIdManager.ts +158 -0
- package/src/core/DocumentParser.ts +10140 -0
- package/src/core/DocumentValidator.ts +372 -0
- package/src/core/Relationship.ts +367 -0
- package/src/core/RelationshipManager.ts +428 -0
- package/src/elements/AlternateContent.ts +42 -0
- package/src/elements/Bookmark.ts +210 -0
- package/src/elements/BookmarkManager.ts +250 -0
- package/src/elements/CLAUDE.md +126 -0
- package/src/elements/Comment.ts +359 -0
- package/src/elements/CommentManager.ts +502 -0
- package/src/elements/CommonTypes.ts +549 -0
- package/src/elements/CustomXml.ts +36 -0
- package/src/elements/Endnote.ts +217 -0
- package/src/elements/EndnoteManager.ts +249 -0
- package/src/elements/Field.ts +1233 -0
- package/src/elements/FieldHelpers.ts +333 -0
- package/src/elements/FontManager.ts +339 -0
- package/src/elements/Footer.ts +269 -0
- package/src/elements/Footnote.ts +217 -0
- package/src/elements/FootnoteManager.ts +249 -0
- package/src/elements/Header.ts +269 -0
- package/src/elements/HeaderFooterManager.ts +219 -0
- package/src/elements/Hyperlink.ts +1146 -0
- package/src/elements/Image.ts +1756 -0
- package/src/elements/ImageManager.ts +432 -0
- package/src/elements/ImageRun.ts +59 -0
- package/src/elements/MathElement.ts +65 -0
- package/src/elements/Paragraph.ts +4287 -0
- package/src/elements/PreservedElement.ts +53 -0
- package/src/elements/PropertyChangeTypes.ts +442 -0
- package/src/elements/RangeMarker.ts +400 -0
- package/src/elements/Revision.ts +1217 -0
- package/src/elements/RevisionContent.ts +73 -0
- package/src/elements/RevisionManager.ts +1070 -0
- package/src/elements/Run.ts +3068 -0
- package/src/elements/Section.ts +1421 -0
- package/src/elements/Shape.ts +873 -0
- package/src/elements/StructuredDocumentTag.ts +978 -0
- package/src/elements/Table.ts +2524 -0
- package/src/elements/TableCell.ts +1586 -0
- package/src/elements/TableGridChange.ts +151 -0
- package/src/elements/TableOfContents.ts +691 -0
- package/src/elements/TableOfContentsElement.ts +89 -0
- package/src/elements/TableRow.ts +906 -0
- package/src/elements/TextBox.ts +768 -0
- package/src/formatting/AbstractNumbering.ts +548 -0
- package/src/formatting/CLAUDE.md +74 -0
- package/src/formatting/NumberingInstance.ts +212 -0
- package/src/formatting/NumberingLevel.ts +1006 -0
- package/src/formatting/NumberingManager.ts +827 -0
- package/src/formatting/Style.ts +1833 -0
- package/src/formatting/StylesManager.ts +1005 -0
- package/src/helpers/CleanupHelper.ts +524 -0
- package/src/images/ImageOptimizer.ts +274 -0
- package/src/index.ts +554 -0
- package/src/managers/CLAUDE.md +47 -0
- package/src/managers/DrawingManager.ts +319 -0
- package/src/tracking/DocumentTrackingContext.ts +643 -0
- package/src/tracking/TrackingContext.ts +173 -0
- package/src/types/compatibility-types.ts +49 -0
- package/src/types/formatting.ts +210 -0
- package/src/types/list-types.ts +152 -0
- package/src/types/settings-types.ts +59 -0
- package/src/types/styleConfig.ts +189 -0
- package/src/utils/CLAUDE.md +153 -0
- package/src/utils/ChangelogGenerator.ts +1581 -0
- package/src/utils/CompatibilityUpgrader.ts +237 -0
- package/src/utils/InMemoryRevisionAcceptor.ts +696 -0
- package/src/utils/MoveOperationHelper.ts +238 -0
- package/src/utils/RevisionAwareProcessor.ts +526 -0
- package/src/utils/RevisionWalker.ts +457 -0
- package/src/utils/SelectiveRevisionAcceptor.ts +683 -0
- package/src/utils/ShadingResolver.ts +107 -0
- package/src/utils/acceptRevisions.ts +714 -0
- package/src/utils/cnfStyleDecoder.ts +217 -0
- package/src/utils/corruptionDetection.ts +345 -0
- package/src/utils/dateFormatting.ts +20 -0
- package/src/utils/deepClone.ts +78 -0
- package/src/utils/diagnostics.ts +129 -0
- package/src/utils/errorHandling.ts +80 -0
- package/src/utils/formatting.ts +213 -0
- package/src/utils/list-detection.ts +274 -0
- package/src/utils/logger.ts +404 -0
- package/src/utils/parsingHelpers.ts +190 -0
- package/src/utils/stripTrackedChanges.ts +353 -0
- package/src/utils/textDiff.ts +100 -0
- package/src/utils/units.ts +421 -0
- package/src/utils/validation.ts +542 -0
- package/src/utils/xmlSanitization.ts +182 -0
- package/src/validation/RevisionAutoFixer.ts +542 -0
- package/src/validation/RevisionValidator.ts +460 -0
- package/src/validation/ValidationRules.ts +338 -0
- package/src/validation/index.ts +30 -0
- package/src/xml/CLAUDE.md +65 -0
- package/src/xml/XMLBuilder.ts +871 -0
- package/src/xml/XMLParser.ts +919 -0
- package/src/zip/CLAUDE.md +55 -0
- package/src/zip/ZipHandler.ts +637 -0
- package/src/zip/ZipReader.ts +299 -0
- package/src/zip/ZipWriter.ts +390 -0
- package/src/zip/errors.ts +69 -0
- package/src/zip/types.ts +116 -0
- package/dist/core/ListNormalizer.d.ts +0 -23
- package/dist/core/ListNormalizer.d.ts.map +0 -1
- package/dist/core/ListNormalizer.js +0 -624
- package/dist/core/ListNormalizer.js.map +0 -1
- package/dist/images/index.d.ts +0 -2
- package/dist/images/index.d.ts.map +0 -1
- package/dist/images/index.js +0 -8
- package/dist/images/index.js.map +0 -1
- package/dist/ms-doc/cfb/CFBReader.d.ts +0 -35
- package/dist/ms-doc/cfb/CFBReader.d.ts.map +0 -1
- package/dist/ms-doc/cfb/CFBReader.js +0 -360
- package/dist/ms-doc/cfb/CFBReader.js.map +0 -1
- package/dist/ms-doc/converter/DocToDocxConverter.d.ts +0 -55
- package/dist/ms-doc/converter/DocToDocxConverter.d.ts.map +0 -1
- package/dist/ms-doc/converter/DocToDocxConverter.js +0 -324
- package/dist/ms-doc/converter/DocToDocxConverter.js.map +0 -1
- package/dist/ms-doc/fib/FIB.d.ts +0 -18
- package/dist/ms-doc/fib/FIB.d.ts.map +0 -1
- package/dist/ms-doc/fib/FIB.js +0 -342
- package/dist/ms-doc/fib/FIB.js.map +0 -1
- package/dist/ms-doc/fields/FieldParser.d.ts +0 -31
- package/dist/ms-doc/fields/FieldParser.d.ts.map +0 -1
- package/dist/ms-doc/fields/FieldParser.js +0 -266
- package/dist/ms-doc/fields/FieldParser.js.map +0 -1
- package/dist/ms-doc/images/PictureExtractor.d.ts +0 -22
- package/dist/ms-doc/images/PictureExtractor.d.ts.map +0 -1
- package/dist/ms-doc/images/PictureExtractor.js +0 -233
- package/dist/ms-doc/images/PictureExtractor.js.map +0 -1
- package/dist/ms-doc/index.d.ts +0 -20
- package/dist/ms-doc/index.d.ts.map +0 -1
- package/dist/ms-doc/index.js +0 -59
- package/dist/ms-doc/index.js.map +0 -1
- package/dist/ms-doc/properties/SPRM.d.ts +0 -210
- package/dist/ms-doc/properties/SPRM.d.ts.map +0 -1
- package/dist/ms-doc/properties/SPRM.js +0 -633
- package/dist/ms-doc/properties/SPRM.js.map +0 -1
- package/dist/ms-doc/sections/SectionParser.d.ts +0 -25
- package/dist/ms-doc/sections/SectionParser.d.ts.map +0 -1
- package/dist/ms-doc/sections/SectionParser.js +0 -214
- package/dist/ms-doc/sections/SectionParser.js.map +0 -1
- package/dist/ms-doc/styles/StyleSheet.d.ts +0 -23
- package/dist/ms-doc/styles/StyleSheet.d.ts.map +0 -1
- package/dist/ms-doc/styles/StyleSheet.js +0 -268
- package/dist/ms-doc/styles/StyleSheet.js.map +0 -1
- package/dist/ms-doc/subdocuments/SubdocumentParser.d.ts +0 -61
- package/dist/ms-doc/subdocuments/SubdocumentParser.d.ts.map +0 -1
- package/dist/ms-doc/subdocuments/SubdocumentParser.js +0 -208
- package/dist/ms-doc/subdocuments/SubdocumentParser.js.map +0 -1
- package/dist/ms-doc/tables/TableParser.d.ts +0 -29
- package/dist/ms-doc/tables/TableParser.d.ts.map +0 -1
- package/dist/ms-doc/tables/TableParser.js +0 -176
- package/dist/ms-doc/tables/TableParser.js.map +0 -1
- package/dist/ms-doc/text/PieceTable.d.ts +0 -21
- package/dist/ms-doc/text/PieceTable.d.ts.map +0 -1
- package/dist/ms-doc/text/PieceTable.js +0 -171
- package/dist/ms-doc/text/PieceTable.js.map +0 -1
- package/dist/ms-doc/types/Constants.d.ts +0 -99
- package/dist/ms-doc/types/Constants.d.ts.map +0 -1
- package/dist/ms-doc/types/Constants.js +0 -102
- package/dist/ms-doc/types/Constants.js.map +0 -1
- package/dist/ms-doc/types/DocTypes.d.ts +0 -368
- package/dist/ms-doc/types/DocTypes.d.ts.map +0 -1
- package/dist/ms-doc/types/DocTypes.js +0 -3
- package/dist/ms-doc/types/DocTypes.js.map +0 -1
- package/dist/tracking/index.d.ts +0 -3
- package/dist/tracking/index.d.ts.map +0 -1
- package/dist/tracking/index.js +0 -6
- package/dist/tracking/index.js.map +0 -1
|
@@ -0,0 +1,906 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TableRow - Represents a row in a table
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { TableCell } from './TableCell';
|
|
6
|
+
import { XMLBuilder, XMLElement } from '../xml/XMLBuilder';
|
|
7
|
+
import { TableBorder, TableBorders } from './Table';
|
|
8
|
+
import {
|
|
9
|
+
BasicShadingPattern,
|
|
10
|
+
RowJustification as CommonRowJustification,
|
|
11
|
+
ShadingConfig,
|
|
12
|
+
buildShadingAttributes,
|
|
13
|
+
} from './CommonTypes';
|
|
14
|
+
import { defaultLogger } from '../utils/logger';
|
|
15
|
+
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// RE-EXPORTED TYPES (for backward compatibility)
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Row justification/alignment options
|
|
22
|
+
* @see CommonTypes.RowJustification
|
|
23
|
+
*/
|
|
24
|
+
export type RowJustification = CommonRowJustification;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Shading pattern values per ECMA-376
|
|
28
|
+
* @see CommonTypes.BasicShadingPattern for the canonical definition
|
|
29
|
+
*/
|
|
30
|
+
export type ShadingPattern = BasicShadingPattern;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Shading configuration
|
|
34
|
+
* @see ShadingConfig in CommonTypes.ts for the canonical definition
|
|
35
|
+
*/
|
|
36
|
+
export type Shading = ShadingConfig;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Table property exceptions - overrides table-level properties for this row
|
|
40
|
+
* Per ECMA-376 Part 1 §17.4.61 (w:tblPrEx)
|
|
41
|
+
*/
|
|
42
|
+
export interface TablePropertyExceptions {
|
|
43
|
+
/** Border overrides for this row */
|
|
44
|
+
borders?: TableBorders;
|
|
45
|
+
/** Shading override for this row */
|
|
46
|
+
shading?: Shading;
|
|
47
|
+
/** Cell spacing override in twips */
|
|
48
|
+
cellSpacing?: number;
|
|
49
|
+
/** Table width override in twips */
|
|
50
|
+
width?: number;
|
|
51
|
+
/** Table indentation override in twips */
|
|
52
|
+
indentation?: number;
|
|
53
|
+
/** Table justification override */
|
|
54
|
+
justification?: RowJustification;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Row formatting options
|
|
59
|
+
*/
|
|
60
|
+
export interface RowFormatting {
|
|
61
|
+
height?: number; // Height in twips
|
|
62
|
+
heightRule?: 'auto' | 'exact' | 'atLeast';
|
|
63
|
+
isHeader?: boolean; // Whether this is a header row
|
|
64
|
+
cantSplit?: boolean; // Prevent row from breaking across pages
|
|
65
|
+
justification?: RowJustification; // Row justification/alignment
|
|
66
|
+
hidden?: boolean; // Hide row
|
|
67
|
+
gridBefore?: number; // Grid columns before first cell
|
|
68
|
+
gridAfter?: number; // Grid columns after last cell
|
|
69
|
+
tablePropertyExceptions?: TablePropertyExceptions; // Table property exceptions for this row
|
|
70
|
+
wBefore?: number; // Width before row in twips (per ECMA-376 §17.4.83)
|
|
71
|
+
wBeforeType?: string; // Width before type (dxa, pct, auto)
|
|
72
|
+
wAfter?: number; // Width after row in twips (per ECMA-376 §17.4.82)
|
|
73
|
+
wAfterType?: string; // Width after type (dxa, pct, auto)
|
|
74
|
+
cellSpacing?: number; // Row-level cell spacing override in twips
|
|
75
|
+
cellSpacingType?: string; // Cell spacing type (dxa, pct)
|
|
76
|
+
cnfStyle?: string; // Conditional formatting bitmask (per ECMA-376 §17.3.1.8)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Table row property change tracking (w:trPrChange)
|
|
81
|
+
* Per ECMA-376 Part 1 §17.13.5.38
|
|
82
|
+
*/
|
|
83
|
+
export interface TrPrChange {
|
|
84
|
+
author: string;
|
|
85
|
+
date: string;
|
|
86
|
+
id: string;
|
|
87
|
+
previousProperties: Record<string, any>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Represents a table row
|
|
92
|
+
*/
|
|
93
|
+
export class TableRow {
|
|
94
|
+
private cells: TableCell[] = [];
|
|
95
|
+
private formatting: RowFormatting;
|
|
96
|
+
/** Parent table reference (if row is inside a table) */
|
|
97
|
+
private _parentTable?: import('./Table').Table;
|
|
98
|
+
/** Tracking context for automatic change tracking */
|
|
99
|
+
private trackingContext?: import('../tracking/TrackingContext').TrackingContext;
|
|
100
|
+
/** Table row property change tracking (w:trPrChange) */
|
|
101
|
+
private trPrChange?: TrPrChange;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates a new TableRow
|
|
105
|
+
* @param cellCount - Number of cells to create (optional)
|
|
106
|
+
* @param formatting - Row formatting options
|
|
107
|
+
*/
|
|
108
|
+
constructor(cellCount?: number, formatting: RowFormatting = {}) {
|
|
109
|
+
this.formatting = formatting;
|
|
110
|
+
|
|
111
|
+
if (cellCount !== undefined && cellCount > 0) {
|
|
112
|
+
for (let i = 0; i < cellCount; i++) {
|
|
113
|
+
const cell = new TableCell();
|
|
114
|
+
cell._setParentRow(this);
|
|
115
|
+
this.cells.push(cell);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Sets the tracking context for automatic change tracking.
|
|
122
|
+
* Called by Document when track changes is enabled.
|
|
123
|
+
* @internal
|
|
124
|
+
*/
|
|
125
|
+
_setTrackingContext(context: import('../tracking/TrackingContext').TrackingContext): void {
|
|
126
|
+
this.trackingContext = context;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Gets the table row property change tracking info
|
|
131
|
+
*/
|
|
132
|
+
getTrPrChange(): TrPrChange | undefined {
|
|
133
|
+
return this.trPrChange;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Sets the table row property change tracking info
|
|
138
|
+
*/
|
|
139
|
+
setTrPrChange(change: TrPrChange | undefined): void {
|
|
140
|
+
this.trPrChange = change;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Clears the table row property change tracking
|
|
145
|
+
*/
|
|
146
|
+
clearTrPrChange(): void {
|
|
147
|
+
this.trPrChange = undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Adds a cell to the row
|
|
152
|
+
* @param cell - Cell to add
|
|
153
|
+
* @returns This row for chaining
|
|
154
|
+
*/
|
|
155
|
+
addCell(cell: TableCell): this {
|
|
156
|
+
this.cells.push(cell);
|
|
157
|
+
cell._setParentRow(this);
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Creates and adds a new cell
|
|
163
|
+
* @param text - Optional text content for the cell
|
|
164
|
+
* @returns The created cell
|
|
165
|
+
*/
|
|
166
|
+
createCell(text?: string): TableCell {
|
|
167
|
+
const cell = new TableCell();
|
|
168
|
+
if (text) {
|
|
169
|
+
cell.createParagraph(text);
|
|
170
|
+
}
|
|
171
|
+
this.cells.push(cell);
|
|
172
|
+
cell._setParentRow(this);
|
|
173
|
+
return cell;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Gets a cell by index
|
|
178
|
+
* @param index - Cell index (0-based)
|
|
179
|
+
* @returns The cell at the index, or undefined
|
|
180
|
+
*/
|
|
181
|
+
getCell(index: number): TableCell | undefined {
|
|
182
|
+
return this.cells[index];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Inserts a cell at the specified index
|
|
187
|
+
* @param index - Position to insert (0-based)
|
|
188
|
+
* @param cell - Cell to insert
|
|
189
|
+
*/
|
|
190
|
+
insertCellAt(index: number, cell: TableCell): void {
|
|
191
|
+
this.cells.splice(index, 0, cell);
|
|
192
|
+
cell._setParentRow(this);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Removes and returns the cell at the specified index
|
|
197
|
+
* @param index - Position to remove (0-based)
|
|
198
|
+
* @returns The removed cell, or undefined if index is out of bounds
|
|
199
|
+
*/
|
|
200
|
+
removeCellAt(index: number): TableCell | undefined {
|
|
201
|
+
if (index < 0 || index >= this.cells.length) return undefined;
|
|
202
|
+
const removed = this.cells.splice(index, 1);
|
|
203
|
+
const cell = removed[0];
|
|
204
|
+
if (cell) cell._setParentRow(undefined);
|
|
205
|
+
return cell;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Gets all cells in the row
|
|
210
|
+
* @returns Array of cells
|
|
211
|
+
*/
|
|
212
|
+
getCells(): TableCell[] {
|
|
213
|
+
return [...this.cells];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Gets the number of cells in the row
|
|
218
|
+
* @returns Number of cells
|
|
219
|
+
*/
|
|
220
|
+
getCellCount(): number {
|
|
221
|
+
return this.cells.length;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Calculates the total grid span of the row (considering column spans)
|
|
226
|
+
*
|
|
227
|
+
* For tables with merged cells, this returns the number of logical columns
|
|
228
|
+
* this row spans based on the columnSpan values of each cell.
|
|
229
|
+
*
|
|
230
|
+
* @returns Total grid span (sum of all cell spans, where unspanned cells count as 1)
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* // Row with 3 cells, middle one spanning 2 columns
|
|
235
|
+
* const row = new TableRow();
|
|
236
|
+
* row.createCell('A'); // span = 1
|
|
237
|
+
* row.createCell('B').setColumnSpan(2); // span = 2
|
|
238
|
+
* row.createCell('C'); // span = 1
|
|
239
|
+
* row.getTotalGridSpan(); // Returns 4
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
getTotalGridSpan(): number {
|
|
243
|
+
let totalSpan = 0;
|
|
244
|
+
for (const cell of this.cells) {
|
|
245
|
+
const formatting = cell.getFormatting();
|
|
246
|
+
totalSpan += formatting.columnSpan || 1;
|
|
247
|
+
}
|
|
248
|
+
return totalSpan;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Validates the row's grid alignment
|
|
253
|
+
*
|
|
254
|
+
* Checks if the total grid span matches the expected column count.
|
|
255
|
+
* Logs a warning if there's a mismatch, which can indicate:
|
|
256
|
+
* - Missing cells (grid span < expected)
|
|
257
|
+
* - Extra cells (grid span > expected)
|
|
258
|
+
* - Incorrect columnSpan values
|
|
259
|
+
*
|
|
260
|
+
* @param expectedColumns - Expected number of columns in the table grid
|
|
261
|
+
* @returns Object with validation result and details
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const result = row.validateGridAlignment(4);
|
|
266
|
+
* if (!result.isValid) {
|
|
267
|
+
* console.log(result.message); // "Row has 3 grid columns but expected 4"
|
|
268
|
+
* }
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
validateGridAlignment(expectedColumns: number): {
|
|
272
|
+
isValid: boolean;
|
|
273
|
+
actualSpan: number;
|
|
274
|
+
message?: string;
|
|
275
|
+
} {
|
|
276
|
+
const actualSpan = this.getTotalGridSpan();
|
|
277
|
+
|
|
278
|
+
if (actualSpan === expectedColumns) {
|
|
279
|
+
return { isValid: true, actualSpan };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const message =
|
|
283
|
+
`Row grid alignment mismatch: has ${actualSpan} grid columns but expected ${expectedColumns}. ` +
|
|
284
|
+
`Cell count: ${this.cells.length}. ` +
|
|
285
|
+
(actualSpan < expectedColumns
|
|
286
|
+
? "Missing cells or incorrect columnSpan values."
|
|
287
|
+
: "Extra cells or excessive columnSpan values.");
|
|
288
|
+
|
|
289
|
+
defaultLogger.warn(`[TableRow] ${message}`);
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
isValid: false,
|
|
293
|
+
actualSpan,
|
|
294
|
+
message,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Sets row height
|
|
300
|
+
* @param twips - Height in twips
|
|
301
|
+
* @param rule - Height rule
|
|
302
|
+
* @returns This row for chaining
|
|
303
|
+
*/
|
|
304
|
+
setHeight(twips: number, rule: RowFormatting['heightRule'] = 'atLeast'): this {
|
|
305
|
+
const prevHeight = this.formatting.height;
|
|
306
|
+
const prevRule = this.formatting.heightRule;
|
|
307
|
+
this.formatting.height = twips;
|
|
308
|
+
this.formatting.heightRule = rule;
|
|
309
|
+
if (this.trackingContext?.isEnabled()) {
|
|
310
|
+
if (prevHeight !== twips) {
|
|
311
|
+
this.trackingContext.trackTableChange(this, 'height', prevHeight, twips);
|
|
312
|
+
}
|
|
313
|
+
if (prevRule !== rule) {
|
|
314
|
+
this.trackingContext.trackTableChange(this, 'heightRule', prevRule, rule);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return this;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Clears the row height, allowing Word to auto-size the row based on content
|
|
322
|
+
* @returns This row for chaining
|
|
323
|
+
*/
|
|
324
|
+
clearHeight(): this {
|
|
325
|
+
delete this.formatting.height;
|
|
326
|
+
delete this.formatting.heightRule;
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Sets whether this is a header row
|
|
332
|
+
* @param isHeader - Whether this is a header row
|
|
333
|
+
* @returns This row for chaining
|
|
334
|
+
*/
|
|
335
|
+
setHeader(isHeader = true): this {
|
|
336
|
+
const prev = this.formatting.isHeader;
|
|
337
|
+
this.formatting.isHeader = isHeader;
|
|
338
|
+
if (this.trackingContext?.isEnabled() && prev !== isHeader) {
|
|
339
|
+
this.trackingContext.trackTableChange(this, 'isHeader', prev, isHeader);
|
|
340
|
+
}
|
|
341
|
+
return this;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Sets whether row can split across pages
|
|
346
|
+
* @param cantSplit - Whether to prevent splitting
|
|
347
|
+
* @returns This row for chaining
|
|
348
|
+
*/
|
|
349
|
+
setCantSplit(cantSplit = true): this {
|
|
350
|
+
const prev = this.formatting.cantSplit;
|
|
351
|
+
this.formatting.cantSplit = cantSplit;
|
|
352
|
+
if (this.trackingContext?.isEnabled() && prev !== cantSplit) {
|
|
353
|
+
this.trackingContext.trackTableChange(this, 'cantSplit', prev, cantSplit);
|
|
354
|
+
}
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Sets row justification/alignment
|
|
360
|
+
* Per ECMA-376 Part 1 §17.4.79 (w:jc)
|
|
361
|
+
* @param alignment - Row justification ('left' | 'center' | 'right' | 'start' | 'end')
|
|
362
|
+
* @returns This row for chaining
|
|
363
|
+
* @example
|
|
364
|
+
* ```typescript
|
|
365
|
+
* row.setJustification('center'); // Center-align the entire row
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
setJustification(alignment: RowJustification): this {
|
|
369
|
+
const prev = this.formatting.justification;
|
|
370
|
+
this.formatting.justification = alignment;
|
|
371
|
+
if (this.trackingContext?.isEnabled() && prev !== alignment) {
|
|
372
|
+
this.trackingContext.trackTableChange(this, 'justification', prev, alignment);
|
|
373
|
+
}
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Sets whether row is hidden
|
|
379
|
+
* Per ECMA-376 Part 1 §17.4.23 (w:hidden)
|
|
380
|
+
* @param hidden - Whether to hide the row
|
|
381
|
+
* @returns This row for chaining
|
|
382
|
+
* @example
|
|
383
|
+
* ```typescript
|
|
384
|
+
* row.setHidden(true); // Hide this row from display
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
setHidden(hidden = true): this {
|
|
388
|
+
const prev = this.formatting.hidden;
|
|
389
|
+
this.formatting.hidden = hidden;
|
|
390
|
+
if (this.trackingContext?.isEnabled() && prev !== hidden) {
|
|
391
|
+
this.trackingContext.trackTableChange(this, 'hidden', prev, hidden);
|
|
392
|
+
}
|
|
393
|
+
return this;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Sets grid columns before first cell
|
|
398
|
+
* Per ECMA-376 Part 1 §17.4.15 (w:gridBefore)
|
|
399
|
+
* Specifies number of grid columns that must be skipped before the first cell
|
|
400
|
+
* @param columns - Number of grid columns to skip before first cell
|
|
401
|
+
* @returns This row for chaining
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* row.setGridBefore(2); // Skip 2 columns before first cell
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
setGridBefore(columns: number): this {
|
|
408
|
+
const prev = this.formatting.gridBefore;
|
|
409
|
+
this.formatting.gridBefore = columns;
|
|
410
|
+
if (this.trackingContext?.isEnabled() && prev !== columns) {
|
|
411
|
+
this.trackingContext.trackTableChange(this, 'gridBefore', prev, columns);
|
|
412
|
+
}
|
|
413
|
+
return this;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Sets grid columns after last cell
|
|
418
|
+
* Per ECMA-376 Part 1 §17.4.14 (w:gridAfter)
|
|
419
|
+
* Specifies number of grid columns that must be left after the last cell
|
|
420
|
+
* @param columns - Number of grid columns to leave after last cell
|
|
421
|
+
* @returns This row for chaining
|
|
422
|
+
* @example
|
|
423
|
+
* ```typescript
|
|
424
|
+
* row.setGridAfter(1); // Leave 1 column after last cell
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
setGridAfter(columns: number): this {
|
|
428
|
+
const prev = this.formatting.gridAfter;
|
|
429
|
+
this.formatting.gridAfter = columns;
|
|
430
|
+
if (this.trackingContext?.isEnabled() && prev !== columns) {
|
|
431
|
+
this.trackingContext.trackTableChange(this, 'gridAfter', prev, columns);
|
|
432
|
+
}
|
|
433
|
+
return this;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Sets table property exceptions for this row
|
|
438
|
+
* Per ECMA-376 Part 1 §17.4.61 (w:tblPrEx)
|
|
439
|
+
*
|
|
440
|
+
* Allows this row to override table-level properties like borders, shading, and cell spacing.
|
|
441
|
+
* Typically used when merging tables or preserving formatting from legacy documents.
|
|
442
|
+
*
|
|
443
|
+
* @param exceptions - Table property exceptions configuration
|
|
444
|
+
* @returns This row for chaining
|
|
445
|
+
* @example
|
|
446
|
+
* ```typescript
|
|
447
|
+
* // Override borders for this row
|
|
448
|
+
* row.setTablePropertyExceptions({
|
|
449
|
+
* borders: {
|
|
450
|
+
* top: { style: 'single', size: 8, color: 'FF0000' },
|
|
451
|
+
* bottom: { style: 'single', size: 8, color: 'FF0000' }
|
|
452
|
+
* },
|
|
453
|
+
* shading: { fill: 'FFFF00', pattern: 'clear' }
|
|
454
|
+
* });
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
setTablePropertyExceptions(exceptions: TablePropertyExceptions): this {
|
|
458
|
+
const prev = this.formatting.tablePropertyExceptions;
|
|
459
|
+
this.formatting.tablePropertyExceptions = exceptions;
|
|
460
|
+
if (this.trackingContext?.isEnabled() && prev !== exceptions) {
|
|
461
|
+
this.trackingContext.trackTableChange(this, 'tablePropertyExceptions', prev, exceptions);
|
|
462
|
+
}
|
|
463
|
+
return this;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Sets width before row (w:wBefore) per ECMA-376 Part 1 §17.4.83
|
|
468
|
+
* @param width - Width in twips
|
|
469
|
+
* @param type - Width type (dxa, pct, auto)
|
|
470
|
+
* @returns This row for chaining
|
|
471
|
+
*/
|
|
472
|
+
setWBefore(width: number, type = 'dxa'): this {
|
|
473
|
+
const prevWidth = this.formatting.wBefore;
|
|
474
|
+
const prevType = this.formatting.wBeforeType;
|
|
475
|
+
this.formatting.wBefore = width;
|
|
476
|
+
this.formatting.wBeforeType = type;
|
|
477
|
+
if (this.trackingContext?.isEnabled()) {
|
|
478
|
+
if (prevWidth !== width) {
|
|
479
|
+
this.trackingContext.trackTableChange(this, 'wBefore', prevWidth, width);
|
|
480
|
+
}
|
|
481
|
+
if (prevType !== type) {
|
|
482
|
+
this.trackingContext.trackTableChange(this, 'wBeforeType', prevType, type);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return this;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Sets width after row (w:wAfter) per ECMA-376 Part 1 §17.4.82
|
|
490
|
+
* @param width - Width in twips
|
|
491
|
+
* @param type - Width type (dxa, pct, auto)
|
|
492
|
+
* @returns This row for chaining
|
|
493
|
+
*/
|
|
494
|
+
setWAfter(width: number, type = 'dxa'): this {
|
|
495
|
+
const prevWidth = this.formatting.wAfter;
|
|
496
|
+
const prevType = this.formatting.wAfterType;
|
|
497
|
+
this.formatting.wAfter = width;
|
|
498
|
+
this.formatting.wAfterType = type;
|
|
499
|
+
if (this.trackingContext?.isEnabled()) {
|
|
500
|
+
if (prevWidth !== width) {
|
|
501
|
+
this.trackingContext.trackTableChange(this, 'wAfter', prevWidth, width);
|
|
502
|
+
}
|
|
503
|
+
if (prevType !== type) {
|
|
504
|
+
this.trackingContext.trackTableChange(this, 'wAfterType', prevType, type);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return this;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Sets row-level cell spacing override (w:tblCellSpacing on row)
|
|
512
|
+
* @param spacing - Cell spacing in twips
|
|
513
|
+
* @param type - Spacing type (dxa, pct)
|
|
514
|
+
* @returns This row for chaining
|
|
515
|
+
*/
|
|
516
|
+
setRowCellSpacing(spacing: number, type = 'dxa'): this {
|
|
517
|
+
const prevSpacing = this.formatting.cellSpacing;
|
|
518
|
+
const prevType = this.formatting.cellSpacingType;
|
|
519
|
+
this.formatting.cellSpacing = spacing;
|
|
520
|
+
this.formatting.cellSpacingType = type;
|
|
521
|
+
if (this.trackingContext?.isEnabled()) {
|
|
522
|
+
if (prevSpacing !== spacing) {
|
|
523
|
+
this.trackingContext.trackTableChange(this, 'cellSpacing', prevSpacing, spacing);
|
|
524
|
+
}
|
|
525
|
+
if (prevType !== type) {
|
|
526
|
+
this.trackingContext.trackTableChange(this, 'cellSpacingType', prevType, type);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return this;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Sets conditional formatting bitmask for this row (w:cnfStyle)
|
|
534
|
+
* Per ECMA-376 Part 1 §17.3.1.8
|
|
535
|
+
* @param cnfStyle - Binary string (e.g., '100000000000' for firstRow)
|
|
536
|
+
* @returns This row for chaining
|
|
537
|
+
*/
|
|
538
|
+
setCnfStyle(cnfStyle: string): this {
|
|
539
|
+
const prev = this.formatting.cnfStyle;
|
|
540
|
+
this.formatting.cnfStyle = cnfStyle;
|
|
541
|
+
if (this.trackingContext?.isEnabled() && prev !== cnfStyle) {
|
|
542
|
+
this.trackingContext.trackTableChange(this, 'cnfStyle', prev, cnfStyle);
|
|
543
|
+
}
|
|
544
|
+
return this;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Gets table property exceptions
|
|
549
|
+
* @returns Table property exceptions or undefined
|
|
550
|
+
*/
|
|
551
|
+
getTablePropertyExceptions(): TablePropertyExceptions | undefined {
|
|
552
|
+
return this.formatting.tablePropertyExceptions;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Gets the row formatting
|
|
557
|
+
* @returns Row formatting
|
|
558
|
+
*/
|
|
559
|
+
getFormatting(): RowFormatting {
|
|
560
|
+
return { ...this.formatting };
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// ============================================================================
|
|
564
|
+
// Individual Formatting Getters
|
|
565
|
+
// ============================================================================
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Gets the row height in twips
|
|
569
|
+
* @returns Height in twips or undefined if not set
|
|
570
|
+
*/
|
|
571
|
+
getHeight(): number | undefined {
|
|
572
|
+
return this.formatting.height;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Gets the row height rule
|
|
577
|
+
* @returns Height rule ('auto', 'exact', 'atLeast') or undefined
|
|
578
|
+
*/
|
|
579
|
+
getHeightRule(): string | undefined {
|
|
580
|
+
return this.formatting.heightRule;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Checks if this row is marked as a header row
|
|
585
|
+
* @returns True if this is a header row
|
|
586
|
+
*/
|
|
587
|
+
getIsHeader(): boolean {
|
|
588
|
+
return this.formatting.isHeader ?? false;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Gets whether the row can split across pages
|
|
593
|
+
* @returns True if row cannot split
|
|
594
|
+
*/
|
|
595
|
+
getCantSplit(): boolean {
|
|
596
|
+
return this.formatting.cantSplit ?? false;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Gets the row justification (alignment)
|
|
601
|
+
* @returns Justification ('left', 'center', 'right') or undefined
|
|
602
|
+
*/
|
|
603
|
+
getJustification(): string | undefined {
|
|
604
|
+
return this.formatting.justification;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Checks if this row is hidden
|
|
609
|
+
* @returns True if row is hidden
|
|
610
|
+
*/
|
|
611
|
+
isHidden(): boolean {
|
|
612
|
+
return this.formatting.hidden ?? false;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Sets the parent table reference for this row.
|
|
617
|
+
* Called by Table when adding rows.
|
|
618
|
+
* @internal
|
|
619
|
+
*/
|
|
620
|
+
_setParentTable(table: import('./Table').Table | undefined): void {
|
|
621
|
+
this._parentTable = table;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Gets the parent table reference for this row.
|
|
626
|
+
* @internal
|
|
627
|
+
*/
|
|
628
|
+
_getParentTable(): import('./Table').Table | undefined {
|
|
629
|
+
return this._parentTable;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Builds XML for table property exceptions
|
|
634
|
+
* Per ECMA-376 Part 1 §17.4.61
|
|
635
|
+
* @private
|
|
636
|
+
*/
|
|
637
|
+
private buildTablePropertyExceptionsXML(exceptions: TablePropertyExceptions): XMLElement[] {
|
|
638
|
+
const children: XMLElement[] = [];
|
|
639
|
+
|
|
640
|
+
// Add table width exception (w:tblW)
|
|
641
|
+
if (exceptions.width !== undefined) {
|
|
642
|
+
children.push(XMLBuilder.wSelf('tblW', {
|
|
643
|
+
'w:w': exceptions.width,
|
|
644
|
+
'w:type': 'dxa'
|
|
645
|
+
}));
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// Add table justification exception (w:jc)
|
|
649
|
+
if (exceptions.justification) {
|
|
650
|
+
children.push(XMLBuilder.wSelf('jc', { 'w:val': exceptions.justification }));
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// Add cell spacing exception (w:tblCellSpacing)
|
|
654
|
+
if (exceptions.cellSpacing !== undefined) {
|
|
655
|
+
children.push(XMLBuilder.wSelf('tblCellSpacing', {
|
|
656
|
+
'w:w': exceptions.cellSpacing,
|
|
657
|
+
'w:type': 'dxa'
|
|
658
|
+
}));
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// Add table indentation exception (w:tblInd)
|
|
662
|
+
if (exceptions.indentation !== undefined) {
|
|
663
|
+
children.push(XMLBuilder.wSelf('tblInd', {
|
|
664
|
+
'w:w': exceptions.indentation,
|
|
665
|
+
'w:type': 'dxa'
|
|
666
|
+
}));
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// Add table borders exception (w:tblBorders)
|
|
670
|
+
if (exceptions.borders) {
|
|
671
|
+
const borderChildren = this.buildBordersXML(exceptions.borders);
|
|
672
|
+
if (borderChildren.length > 0) {
|
|
673
|
+
children.push(XMLBuilder.w('tblBorders', undefined, borderChildren));
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// Add shading exception (w:shd)
|
|
678
|
+
if (exceptions.shading) {
|
|
679
|
+
const shdAttrs: Record<string, string> = {};
|
|
680
|
+
if (exceptions.shading.pattern) shdAttrs['w:val'] = exceptions.shading.pattern;
|
|
681
|
+
if (exceptions.shading.color) shdAttrs['w:color'] = exceptions.shading.color;
|
|
682
|
+
if (exceptions.shading.fill) shdAttrs['w:fill'] = exceptions.shading.fill;
|
|
683
|
+
if (exceptions.shading.themeColor) shdAttrs['w:themeColor'] = exceptions.shading.themeColor;
|
|
684
|
+
if (exceptions.shading.themeFill) shdAttrs['w:themeFill'] = exceptions.shading.themeFill;
|
|
685
|
+
if (exceptions.shading.themeFillShade) shdAttrs['w:themeFillShade'] = exceptions.shading.themeFillShade;
|
|
686
|
+
if (exceptions.shading.themeFillTint) shdAttrs['w:themeFillTint'] = exceptions.shading.themeFillTint;
|
|
687
|
+
if (exceptions.shading.themeShade) shdAttrs['w:themeShade'] = exceptions.shading.themeShade;
|
|
688
|
+
if (exceptions.shading.themeTint) shdAttrs['w:themeTint'] = exceptions.shading.themeTint;
|
|
689
|
+
children.push(XMLBuilder.w('shd', shdAttrs));
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
return children;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Builds XML for table borders
|
|
697
|
+
* @private
|
|
698
|
+
*/
|
|
699
|
+
private buildBordersXML(borders: TableBorders): XMLElement[] {
|
|
700
|
+
const children: XMLElement[] = [];
|
|
701
|
+
|
|
702
|
+
const borderNames: (keyof TableBorders)[] = ['top', 'left', 'bottom', 'right', 'insideH', 'insideV'];
|
|
703
|
+
|
|
704
|
+
for (const name of borderNames) {
|
|
705
|
+
const border = borders[name];
|
|
706
|
+
if (border) {
|
|
707
|
+
const attrs: Record<string, string | number> = {};
|
|
708
|
+
if (border.style) attrs['w:val'] = border.style;
|
|
709
|
+
if (border.size !== undefined) attrs['w:sz'] = border.size;
|
|
710
|
+
if (border.space !== undefined) attrs['w:space'] = border.space;
|
|
711
|
+
if (border.color) attrs['w:color'] = border.color;
|
|
712
|
+
|
|
713
|
+
if (Object.keys(attrs).length > 0) {
|
|
714
|
+
children.push(XMLBuilder.wSelf(name, attrs));
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
return children;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Converts the row to WordprocessingML XML element
|
|
724
|
+
* @returns XMLElement representing the row
|
|
725
|
+
*/
|
|
726
|
+
toXML(): XMLElement {
|
|
727
|
+
const trPrChildren: XMLElement[] = [];
|
|
728
|
+
|
|
729
|
+
// Ordered per CT_TrPr (ECMA-376 §17.4.79):
|
|
730
|
+
// cnfStyle → divId → gridBefore → gridAfter → wBefore → wAfter →
|
|
731
|
+
// cantSplit → trHeight → tblHeader → tblCellSpacing → jc → hidden
|
|
732
|
+
|
|
733
|
+
// 1. cnfStyle (conditional formatting bitmask)
|
|
734
|
+
if (this.formatting.cnfStyle) {
|
|
735
|
+
trPrChildren.push(XMLBuilder.wSelf('cnfStyle', { 'w:val': this.formatting.cnfStyle }));
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// 2. (divId not supported)
|
|
739
|
+
|
|
740
|
+
// 3. gridBefore
|
|
741
|
+
if (this.formatting.gridBefore !== undefined) {
|
|
742
|
+
trPrChildren.push(XMLBuilder.wSelf('gridBefore', { 'w:val': this.formatting.gridBefore }));
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// 4. gridAfter
|
|
746
|
+
if (this.formatting.gridAfter !== undefined) {
|
|
747
|
+
trPrChildren.push(XMLBuilder.wSelf('gridAfter', { 'w:val': this.formatting.gridAfter }));
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// 5. wBefore
|
|
751
|
+
if (this.formatting.wBefore !== undefined) {
|
|
752
|
+
trPrChildren.push(XMLBuilder.wSelf('wBefore', {
|
|
753
|
+
'w:w': this.formatting.wBefore,
|
|
754
|
+
'w:type': this.formatting.wBeforeType || 'dxa',
|
|
755
|
+
}));
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// 6. wAfter
|
|
759
|
+
if (this.formatting.wAfter !== undefined) {
|
|
760
|
+
trPrChildren.push(XMLBuilder.wSelf('wAfter', {
|
|
761
|
+
'w:w': this.formatting.wAfter,
|
|
762
|
+
'w:type': this.formatting.wAfterType || 'dxa',
|
|
763
|
+
}));
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// 7. cantSplit
|
|
767
|
+
if (this.formatting.cantSplit) {
|
|
768
|
+
trPrChildren.push(XMLBuilder.wSelf('cantSplit'));
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// 8. trHeight
|
|
772
|
+
if (this.formatting.height !== undefined) {
|
|
773
|
+
const attrs: Record<string, string | number> = {
|
|
774
|
+
'w:val': this.formatting.height,
|
|
775
|
+
};
|
|
776
|
+
if (this.formatting.heightRule) {
|
|
777
|
+
attrs['w:hRule'] = this.formatting.heightRule;
|
|
778
|
+
}
|
|
779
|
+
trPrChildren.push(XMLBuilder.wSelf('trHeight', attrs));
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// 9. tblHeader
|
|
783
|
+
if (this.formatting.isHeader) {
|
|
784
|
+
trPrChildren.push(XMLBuilder.wSelf('tblHeader'));
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// 10. tblCellSpacing
|
|
788
|
+
if (this.formatting.cellSpacing !== undefined) {
|
|
789
|
+
trPrChildren.push(XMLBuilder.wSelf('tblCellSpacing', {
|
|
790
|
+
'w:w': this.formatting.cellSpacing,
|
|
791
|
+
'w:type': this.formatting.cellSpacingType || 'dxa',
|
|
792
|
+
}));
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// 11. jc (map 'start'/'end' to valid ST_JcTable values)
|
|
796
|
+
if (this.formatting.justification) {
|
|
797
|
+
const jcMap: Record<string, string> = { start: 'left', end: 'right' };
|
|
798
|
+
const jcVal = jcMap[this.formatting.justification] || this.formatting.justification;
|
|
799
|
+
trPrChildren.push(XMLBuilder.wSelf('jc', { 'w:val': jcVal }));
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// 12. hidden
|
|
803
|
+
if (this.formatting.hidden) {
|
|
804
|
+
trPrChildren.push(XMLBuilder.wSelf('hidden'));
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
// Add table row property change (w:trPrChange) per ECMA-376 Part 1 §17.13.5.38
|
|
808
|
+
// Must be last child of w:trPr
|
|
809
|
+
if (this.trPrChange) {
|
|
810
|
+
const changeAttrs: Record<string, string | number> = {
|
|
811
|
+
'w:id': this.trPrChange.id,
|
|
812
|
+
'w:author': this.trPrChange.author,
|
|
813
|
+
'w:date': this.trPrChange.date,
|
|
814
|
+
};
|
|
815
|
+
const prevTrPrChildren: XMLElement[] = [];
|
|
816
|
+
const prev = this.trPrChange.previousProperties;
|
|
817
|
+
if (prev) {
|
|
818
|
+
// Ordered per CT_TrPr: cnfStyle → gridBefore → gridAfter → wBefore → wAfter →
|
|
819
|
+
// cantSplit → trHeight → tblHeader → tblCellSpacing → jc → hidden
|
|
820
|
+
if (prev.cnfStyle) {
|
|
821
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('cnfStyle', { 'w:val': prev.cnfStyle }));
|
|
822
|
+
}
|
|
823
|
+
if (prev.gridBefore !== undefined) {
|
|
824
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('gridBefore', { 'w:val': prev.gridBefore }));
|
|
825
|
+
}
|
|
826
|
+
if (prev.gridAfter !== undefined) {
|
|
827
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('gridAfter', { 'w:val': prev.gridAfter }));
|
|
828
|
+
}
|
|
829
|
+
if (prev.wBefore !== undefined) {
|
|
830
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('wBefore', {
|
|
831
|
+
'w:w': prev.wBefore,
|
|
832
|
+
'w:type': prev.wBeforeType || 'dxa',
|
|
833
|
+
}));
|
|
834
|
+
}
|
|
835
|
+
if (prev.wAfter !== undefined) {
|
|
836
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('wAfter', {
|
|
837
|
+
'w:w': prev.wAfter,
|
|
838
|
+
'w:type': prev.wAfterType || 'dxa',
|
|
839
|
+
}));
|
|
840
|
+
}
|
|
841
|
+
if (prev.cantSplit) {
|
|
842
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('cantSplit'));
|
|
843
|
+
}
|
|
844
|
+
if (prev.height !== undefined) {
|
|
845
|
+
const heightAttrs: Record<string, string | number> = { 'w:val': prev.height };
|
|
846
|
+
if (prev.heightRule) heightAttrs['w:hRule'] = prev.heightRule;
|
|
847
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('trHeight', heightAttrs));
|
|
848
|
+
}
|
|
849
|
+
if (prev.isHeader) {
|
|
850
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('tblHeader'));
|
|
851
|
+
}
|
|
852
|
+
if (prev.cellSpacing !== undefined) {
|
|
853
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('tblCellSpacing', {
|
|
854
|
+
'w:w': prev.cellSpacing,
|
|
855
|
+
'w:type': prev.cellSpacingType || 'dxa',
|
|
856
|
+
}));
|
|
857
|
+
}
|
|
858
|
+
if (prev.justification) {
|
|
859
|
+
const jcPrevMap: Record<string, string> = { start: 'left', end: 'right' };
|
|
860
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('jc', { 'w:val': jcPrevMap[prev.justification] || prev.justification }));
|
|
861
|
+
}
|
|
862
|
+
if (prev.hidden) {
|
|
863
|
+
prevTrPrChildren.push(XMLBuilder.wSelf('hidden'));
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
const prevTrPr = XMLBuilder.w('trPr', undefined, prevTrPrChildren);
|
|
867
|
+
trPrChildren.push(XMLBuilder.w('trPrChange', changeAttrs, [prevTrPr]));
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// Build row element
|
|
871
|
+
const rowChildren: XMLElement[] = [];
|
|
872
|
+
|
|
873
|
+
// Add row properties if there are any
|
|
874
|
+
if (trPrChildren.length > 0) {
|
|
875
|
+
rowChildren.push(XMLBuilder.w('trPr', undefined, trPrChildren));
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// Add table property exceptions (tblPrEx) if present
|
|
879
|
+
if (this.formatting.tablePropertyExceptions) {
|
|
880
|
+
const tblPrExChildren = this.buildTablePropertyExceptionsXML(this.formatting.tablePropertyExceptions);
|
|
881
|
+
if (tblPrExChildren.length > 0) {
|
|
882
|
+
rowChildren.push(XMLBuilder.w('tblPrEx', undefined, tblPrExChildren));
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// Add all cells - each cell is independent
|
|
887
|
+
// Note: gridSpan (columnSpan) means a single cell spans multiple columns in the grid,
|
|
888
|
+
// it does NOT mean subsequent cells should be skipped. Each cell in the array
|
|
889
|
+
// represents a distinct cell that should be output to the XML.
|
|
890
|
+
for (const cell of this.cells) {
|
|
891
|
+
rowChildren.push(cell.toXML());
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
return XMLBuilder.w('tr', undefined, rowChildren);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* Creates a new TableRow
|
|
899
|
+
* @param cellCount - Number of cells to create
|
|
900
|
+
* @param formatting - Row formatting
|
|
901
|
+
* @returns New TableRow instance
|
|
902
|
+
*/
|
|
903
|
+
static create(cellCount?: number, formatting?: RowFormatting): TableRow {
|
|
904
|
+
return new TableRow(cellCount, formatting);
|
|
905
|
+
}
|
|
906
|
+
}
|