diff --git a/src/export/packer/next-compiler.spec.ts b/src/export/packer/next-compiler.spec.ts index e5336cbcf5..3ffdda7953 100644 --- a/src/export/packer/next-compiler.spec.ts +++ b/src/export/packer/next-compiler.spec.ts @@ -23,7 +23,7 @@ describe("Compiler", () => { const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name); expect(fileNames).is.an.instanceof(Array); - expect(fileNames).has.length(16); + expect(fileNames).has.length(17); expect(fileNames).to.include("word/document.xml"); expect(fileNames).to.include("word/styles.xml"); expect(fileNames).to.include("docProps/core.xml"); @@ -33,6 +33,7 @@ describe("Compiler", () => { expect(fileNames).to.include("word/footnotes.xml"); expect(fileNames).to.include("word/_rels/footnotes.xml.rels"); expect(fileNames).to.include("word/settings.xml"); + expect(fileNames).to.include("word/comments.xml"); expect(fileNames).to.include("word/_rels/document.xml.rels"); expect(fileNames).to.include("[Content_Types].xml"); expect(fileNames).to.include("_rels/.rels"); @@ -76,7 +77,7 @@ describe("Compiler", () => { const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name); expect(fileNames).is.an.instanceof(Array); - expect(fileNames).has.length(24); + expect(fileNames).has.length(25); expect(fileNames).to.include("word/header1.xml"); expect(fileNames).to.include("word/_rels/header1.xml.rels"); diff --git a/src/export/packer/next-compiler.ts b/src/export/packer/next-compiler.ts index fd6110601b..90d08a2232 100644 --- a/src/export/packer/next-compiler.ts +++ b/src/export/packer/next-compiler.ts @@ -406,6 +406,10 @@ export class Compiler { }, Comments: { data: (() => { + if (!file.Comments) { + return; + } + const data = xml( this.formatter.format(file.Comments, { viewWrapper: file.Document, diff --git a/src/export/packer/packer.ts b/src/export/packer/packer.ts index 87ee47666b..b32cd0aa8d 100644 --- a/src/export/packer/packer.ts +++ b/src/export/packer/packer.ts @@ -8,7 +8,7 @@ export enum PrettityType { NONE = "", WITH_2_BLANKS = " ", WITH_4_BLANKS = " ", - WITH_TAB = "\t" + WITH_TAB = "\t", } export class Packer { diff --git a/src/file/content-types/content-types.spec.ts b/src/file/content-types/content-types.spec.ts index 57d992f83d..93fca7c8e1 100644 --- a/src/file/content-types/content-types.spec.ts +++ b/src/file/content-types/content-types.spec.ts @@ -102,7 +102,7 @@ describe("ContentTypes", () => { contentTypes.addFooter(102); const tree = new Formatter().format(contentTypes); - expect(tree["Types"][16]).to.deep.equal({ + expect(tree["Types"][17]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", @@ -111,7 +111,7 @@ describe("ContentTypes", () => { }, }); - expect(tree["Types"][17]).to.deep.equal({ + expect(tree["Types"][18]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", @@ -128,7 +128,7 @@ describe("ContentTypes", () => { contentTypes.addHeader(202); const tree = new Formatter().format(contentTypes); - expect(tree["Types"][16]).to.deep.equal({ + expect(tree["Types"][17]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", @@ -137,7 +137,7 @@ describe("ContentTypes", () => { }, }); - expect(tree["Types"][17]).to.deep.equal({ + expect(tree["Types"][18]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", diff --git a/src/file/core-properties/properties.ts b/src/file/core-properties/properties.ts index 5c3dbd42d8..7269518bdd 100644 --- a/src/file/core-properties/properties.ts +++ b/src/file/core-properties/properties.ts @@ -1,5 +1,6 @@ -import { Comments } from './../paragraph/run/comment-run'; +import { Comments } from "file/paragraph/run/comment-run"; import { StringContainer, XmlComponent } from "file/xml-components"; + import { ICustomPropertyOptions } from "../custom-properties"; import { IDocumentBackgroundOptions } from "../document"; diff --git a/src/file/document/document.spec.ts b/src/file/document/document.spec.ts index f6137bde70..6cea17d009 100644 --- a/src/file/document/document.spec.ts +++ b/src/file/document/document.spec.ts @@ -31,11 +31,27 @@ describe("Document", () => { "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main", "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml", "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml", + "xmlns:w16": "http://schemas.microsoft.com/office/word/2018/wordml", + "xmlns:w16cex": "http://schemas.microsoft.com/office/word/2018/wordml/cex", + "xmlns:w16cid": "http://schemas.microsoft.com/office/word/2016/wordml/cid", + "xmlns:w16sdtdh": "http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash", + "xmlns:w16se": "http://schemas.microsoft.com/office/word/2015/wordml/symex", "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml", "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", "mc:Ignorable": "w14 w15 wp14", + "xmlns:aink": "http://schemas.microsoft.com/office/drawing/2016/ink", + "xmlns:am3d": "http://schemas.microsoft.com/office/drawing/2017/model3d", + "xmlns:cx": "http://schemas.microsoft.com/office/drawing/2014/chartex", + "xmlns:cx1": "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex", + "xmlns:cx2": "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex", + "xmlns:cx3": "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex", + "xmlns:cx4": "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex", + "xmlns:cx5": "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex", + "xmlns:cx6": "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex", + "xmlns:cx7": "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex", + "xmlns:cx8": "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex", }, }, { diff --git a/src/file/file.ts b/src/file/file.ts index 48dd71b844..20d29d0ed9 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -1,4 +1,3 @@ -import { Comments } from "./paragraph/run/comment-run"; import { AppProperties } from "./app-properties/app-properties"; import { ContentTypes } from "./content-types/content-types"; import { CoreProperties, IPropertiesOptions } from "./core-properties"; @@ -13,6 +12,7 @@ import { HeaderWrapper, IDocumentHeader } from "./header-wrapper"; import { Media } from "./media"; import { Numbering } from "./numbering"; import { Paragraph } from "./paragraph"; +import { Comments } from "./paragraph/run/comment-run"; import { Relationships } from "./relationships"; import { Settings } from "./settings"; import { Styles } from "./styles"; diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index 4f3919196d..4257816375 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -1,6 +1,4 @@ -import { CommentRangeStart, CommentRangeEnd, CommentReference, Comments, Comment } from "./run/comment-run"; // http://officeopenxml.com/WPparagraph.php - import { uniqueId } from "convenience-functions"; import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run"; import { IContext, IXmlableObject, XmlComponent } from "file/xml-components"; @@ -12,6 +10,7 @@ import { Bookmark, ConcreteHyperlink, ExternalHyperlink, InternalHyperlink } fro import { Math } from "./math"; import { IParagraphPropertiesOptions, ParagraphProperties } from "./properties"; import { ImageRun, Run, SequentialIdentifier, SimpleField, SimpleMailMergeField, SymbolRun, TextRun } from "./run"; +import { Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments } from "./run/comment-run"; export type ParagraphChild = | TextRun diff --git a/src/file/paragraph/run/comment-run.ts b/src/file/paragraph/run/comment-run.ts index f65bb08c5b..dea19b6147 100644 --- a/src/file/paragraph/run/comment-run.ts +++ b/src/file/paragraph/run/comment-run.ts @@ -1,6 +1,7 @@ +import { Paragraph } from "file/paragraph"; +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + import { TextRun } from "./text-run"; -import { Paragraph } from "./../paragraph"; -import { XmlAttributeComponent, XmlComponent } from "../../../file/xml-components"; interface ICommentOptions { readonly id: string; @@ -119,6 +120,7 @@ interface ICommentsAttrs { export class CommentRangeStart extends XmlComponent { constructor(options: ICommentOptions) { super("w:commentRangeStart"); + this.root.push(new CommentAttributes(options)); } } @@ -126,6 +128,7 @@ export class CommentRangeStart extends XmlComponent { export class CommentRangeEnd extends XmlComponent { constructor(options: ICommentOptions) { super("w:commentRangeEnd"); + this.root.push(new CommentAttributes(options)); } } @@ -133,6 +136,7 @@ export class CommentRangeEnd extends XmlComponent { export class CommentReference extends XmlComponent { constructor(options: ICommentOptions) { super("w:commentReference"); + this.root.push(new CommentAttributes(options)); } } @@ -140,14 +144,18 @@ export class CommentReference extends XmlComponent { export class Comment extends XmlComponent { constructor(options: ICommentOptions, text: string) { super("w:comment"); + this.root.push(new CommentAttributes(options)); + this.addChildElement(new Paragraph({ children: [new TextRun(text)] })); } } export class Comments extends XmlComponent { constructor(comments: Comment[]) { super("w:comments"); + this.root.push(new RootCommentsAttributes(COMMENT_ATTRIBUTES_MAP)); + comments.forEach((comment) => { this.addChildElement(comment); });