added InsertedTextRun and DeletedTextRun for Revision Tracking

This commit is contained in:
Thomas Jansen
2020-09-24 10:24:00 +02:00
parent 2adfe532dd
commit 09db2c528a
5 changed files with 158 additions and 0 deletions

View File

@ -0,0 +1,72 @@
import { SpaceType } from "file/space-type";
import { XmlComponent, XmlAttributeComponent } from "file/xml-components";
import { TextRun } from "../index";
export interface ITrackRevisionAttributesProperties {
readonly id: number;
readonly author: string;
readonly date: string;
}
export class TrackRevisionAttributes extends XmlAttributeComponent<ITrackRevisionAttributesProperties> {
protected readonly xmlKeys = {
id: "w:id",
author: "w:author",
date: "w:date",
};
}
export interface IInsertedTextRunOptions extends ITrackRevisionAttributesProperties {
readonly child: TextRun
}
export interface IDeletedTextRunOptions extends ITrackRevisionAttributesProperties {
readonly text: string
}
export class InsertedTextRun extends XmlComponent {
constructor(options: IInsertedTextRunOptions) {
super("w:ins");
this.root.push(
new TrackRevisionAttributes({
id: options.id,
author: options.author,
date: options.date,
})
);
this.addChildElement(options.child);
}
}
export class DeletedTextRunWrapper extends XmlComponent {
constructor(text: string) {
super("w:r");
this.root.push(new DeletedText(text));
}
}
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
protected readonly xmlKeys = { space: "xml:space" };
}
export class DeletedText extends XmlComponent {
constructor(text: string) {
super("w:delText");
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
this.root.push(text);
}
}
export class DeletedTextRun extends XmlComponent {
constructor(options: IDeletedTextRunOptions) {
super("w:del");
this.root.push(
new TrackRevisionAttributes({
id: options.id,
author: options.author,
date: options.date,
})
);
this.addChildElement(new DeletedTextRunWrapper(options.text));
}
}