Change table methods and document it
This commit is contained in:
@ -14,7 +14,12 @@ export class TableCell extends XmlComponent {
|
||||
this.root.push(this.properties);
|
||||
}
|
||||
|
||||
public addContent(content: Paragraph | Table): TableCell {
|
||||
public addParagraph(content: Paragraph): TableCell {
|
||||
this.root.push(content);
|
||||
return this;
|
||||
}
|
||||
|
||||
public addTable(content: Table): TableCell {
|
||||
this.root.push(content);
|
||||
return this;
|
||||
}
|
||||
@ -35,11 +40,12 @@ export class TableCell extends XmlComponent {
|
||||
|
||||
public createParagraph(text?: string): Paragraph {
|
||||
const para = new Paragraph(text);
|
||||
this.addContent(para);
|
||||
this.addParagraph(para);
|
||||
|
||||
return para;
|
||||
}
|
||||
|
||||
public get CellProperties(): TableCellProperties {
|
||||
public get Properties(): TableCellProperties {
|
||||
return this.properties;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ export class TableRow extends XmlComponent {
|
||||
|
||||
public addGridSpan(index: number, cellSpan: number): TableCell {
|
||||
const remainCell = this.cells[index];
|
||||
remainCell.CellProperties.addGridSpan(cellSpan);
|
||||
remainCell.Properties.addGridSpan(cellSpan);
|
||||
this.cells.splice(index + 1, cellSpan - 1);
|
||||
this.root.splice(index + 2, cellSpan - 1);
|
||||
|
||||
|
@ -111,19 +111,19 @@ describe("Table", () => {
|
||||
table
|
||||
.getRow(0)
|
||||
.getCell(0)
|
||||
.addContent(new Paragraph("A1"));
|
||||
.addParagraph(new Paragraph("A1"));
|
||||
table
|
||||
.getRow(0)
|
||||
.getCell(1)
|
||||
.addContent(new Paragraph("B1"));
|
||||
.addParagraph(new Paragraph("B1"));
|
||||
table
|
||||
.getRow(1)
|
||||
.getCell(0)
|
||||
.addContent(new Paragraph("A2"));
|
||||
.addParagraph(new Paragraph("A2"));
|
||||
table
|
||||
.getRow(1)
|
||||
.getCell(1)
|
||||
.addContent(new Paragraph("B2"));
|
||||
.addParagraph(new Paragraph("B2"));
|
||||
const tree = new Formatter().format(table);
|
||||
const cell = (c) => ({
|
||||
"w:tc": [
|
||||
@ -149,10 +149,10 @@ describe("Table", () => {
|
||||
describe("#getCell", () => {
|
||||
it("returns the correct cell", () => {
|
||||
const table = new Table(2, 2);
|
||||
table.getCell(0, 0).addContent(new Paragraph("A1"));
|
||||
table.getCell(0, 1).addContent(new Paragraph("B1"));
|
||||
table.getCell(1, 0).addContent(new Paragraph("A2"));
|
||||
table.getCell(1, 1).addContent(new Paragraph("B2"));
|
||||
table.getCell(0, 0).addParagraph(new Paragraph("A1"));
|
||||
table.getCell(0, 1).addParagraph(new Paragraph("B1"));
|
||||
table.getCell(1, 0).addParagraph(new Paragraph("A2"));
|
||||
table.getCell(1, 1).addParagraph(new Paragraph("B2"));
|
||||
const tree = new Formatter().format(table);
|
||||
const cell = (c) => ({
|
||||
"w:tc": [
|
||||
@ -232,7 +232,7 @@ describe("Table", () => {
|
||||
|
||||
it("inserts a paragraph at the end of the cell even if it has a child table", () => {
|
||||
const parentTable = new Table(1, 1);
|
||||
parentTable.getCell(0, 0).addContent(new Table(1, 1));
|
||||
parentTable.getCell(0, 0).addTable(new Table(1, 1));
|
||||
const tree = new Formatter().format(parentTable);
|
||||
expect(tree)
|
||||
.to.have.property("w:tbl")
|
||||
@ -251,7 +251,7 @@ describe("Table", () => {
|
||||
|
||||
it("does not insert a paragraph if it already ends with one", () => {
|
||||
const parentTable = new Table(1, 1);
|
||||
parentTable.getCell(0, 0).addContent(new Paragraph("Hello"));
|
||||
parentTable.getCell(0, 0).addParagraph(new Paragraph("Hello"));
|
||||
const tree = new Formatter().format(parentTable);
|
||||
expect(tree)
|
||||
.to.have.property("w:tbl")
|
||||
|
Reference in New Issue
Block a user