Change API of track revisions to declarative

This commit is contained in:
Dolan
2020-11-04 00:00:16 +00:00
parent 37e610d2b3
commit 34b2029efe
4 changed files with 37 additions and 12 deletions

View File

@ -1,7 +1,19 @@
// Track Revisions aka. "Track Changes" // Track Revisions aka. "Track Changes"
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun, ShadingType, DeletedTextRun, InsertedTextRun, Footer, PageNumber, AlignmentType, FootnoteReferenceRun } from "../build"; import {
AlignmentType,
DeletedTextRun,
Document,
Footer,
FootnoteReferenceRun,
InsertedTextRun,
Packer,
PageNumber,
Paragraph,
ShadingType,
TextRun,
} from "../build";
/* /*
For reference, see For reference, see
@ -30,19 +42,20 @@ const doc = new Document({
id: 1, id: 1,
author: "Firstname Lastname", author: "Firstname Lastname",
date: "2020-10-06T09:05:00Z", date: "2020-10-06T09:05:00Z",
})
]
}), }),
], ],
}),
],
features: {
trackRevisions: true,
},
}); });
doc.Settings.addTrackRevisions()
const paragraph = new Paragraph({ const paragraph = new Paragraph({
children: [ children: [
new TextRun("This is a simple demo "), new TextRun("This is a simple demo "),
new TextRun({ new TextRun({
text: "on how to " text: "on how to ",
}), }),
new InsertedTextRun({ new InsertedTextRun({
text: "mark a text as an insertion ", text: "mark a text as an insertion ",
@ -55,7 +68,7 @@ const paragraph = new Paragraph({
id: 1, id: 1,
author: "Firstname Lastname", author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z", date: "2020-10-06T09:00:00Z",
}) }),
], ],
}); });

View File

@ -53,6 +53,9 @@ In addtion to marking text as inserted or deleted, change tracking can also be a
```ts ```ts
import { Document } from "docx"; import { Document } from "docx";
const doc = new Document({}); const doc = new Document({
doc.Settings.addTrackRevisions() features: {
trackRevisions: true,
},
});
``` ```

View File

@ -34,6 +34,9 @@ export interface IPropertiesOptions {
readonly [key: string]: IInternalHyperlinkDefinition | IExternalHyperlinkDefinition; readonly [key: string]: IInternalHyperlinkDefinition | IExternalHyperlinkDefinition;
}; };
readonly background?: IDocumentBackgroundOptions; readonly background?: IDocumentBackgroundOptions;
readonly features?: {
readonly trackRevisions?: boolean;
};
} }
export class CoreProperties extends XmlComponent { export class CoreProperties extends XmlComponent {

View File

@ -170,6 +170,12 @@ export class File {
this.hyperlinkCache = cache; this.hyperlinkCache = cache;
} }
if (options.features) {
if (options.features.trackRevisions) {
this.settings.addTrackRevisions();
}
}
} }
public addSection({ public addSection({