Merge pull request #2015 from dolanmiu/feat/allow-for-children-in-comments
#1988 Allow for children in comments
This commit is contained in:
@ -5,7 +5,34 @@ import { Document, Packer, Paragraph, TextRun, CommentRangeStart, CommentRangeEn
|
||||
|
||||
const doc = new Document({
|
||||
comments: {
|
||||
children: [{ id: 0, author: "Ray Chen", date: new Date(), text: "comment text content" }],
|
||||
children: [
|
||||
{
|
||||
id: 0,
|
||||
author: "Ray Chen",
|
||||
date: new Date(),
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "some initial text content",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "comment text content",
|
||||
}),
|
||||
new TextRun({ text: "", break: 1 }),
|
||||
new TextRun({
|
||||
text: "More text here",
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
sections: [
|
||||
{
|
||||
|
@ -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"),
|
||||
},
|
||||
],
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user