#1988 Allow for children in comments

This commit is contained in:
Dolan Miu
2023-03-19 00:18:38 +00:00
parent d6256d2acb
commit d5b495df5b
3 changed files with 40 additions and 11 deletions

View File

@ -2,6 +2,8 @@ import { expect } from "chai";
import * as sinon from "sinon";
import { Formatter } from "@export/formatter";
import { Paragraph } from "../paragraph";
import { Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments } from "./comment-run";
describe("CommentRangeStart", () => {
@ -56,7 +58,7 @@ describe("Comment", () => {
it("should create", () => {
const component = new Comment({
id: 0,
text: "test-comment",
children: [new Paragraph("test-comment")],
date: new Date("1999-01-01T00:00:00.000Z"),
});
const tree = new Formatter().format(component);
@ -88,7 +90,7 @@ describe("Comment", () => {
it("should create by using default date", () => {
const component = new Comment({
id: 0,
text: "test-comment",
children: [new Paragraph("test-comment")],
});
const tree = new Formatter().format(component);
expect(tree).to.deep.equal({
@ -125,12 +127,12 @@ describe("Comments", () => {
children: [
{
id: 0,
text: "test-comment",
children: [new Paragraph("test-comment")],
date: new Date("1999-01-01T00:00:00.000Z"),
},
{
id: 1,
text: "test-comment-2",
children: [new Paragraph("test-comment-2")],
date: new Date("1999-01-01T00:00:00.000Z"),
},
],

View File

@ -1,11 +1,9 @@
import { Paragraph } from "@file/paragraph";
import { FileChild } from "@file/file-child";
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { TextRun } from "./text-run";
export interface ICommentOptions {
readonly id: number;
readonly text: string;
readonly children: readonly FileChild[];
readonly initials?: string;
readonly author?: string;
readonly date?: Date;
@ -120,7 +118,7 @@ export class CommentReference extends XmlComponent {
}
export class Comment extends XmlComponent {
public constructor({ id, initials, author, date = new Date(), text }: ICommentOptions) {
public constructor({ id, initials, author, date = new Date(), children }: ICommentOptions) {
super("w:comment");
this.root.push(
@ -132,7 +130,9 @@ export class Comment extends XmlComponent {
}),
);
this.root.push(new Paragraph({ children: [new TextRun(text)] }));
for (const child of children) {
this.root.push(child);
}
}
}
export class Comments extends XmlComponent {