Fix ordering of elements in table, table-cell, table-properties, table-cell-properties, table-cell-margin

This commit is contained in:
Tom Hunkapiller
2021-05-20 01:03:09 +03:00
parent 45130bed0b
commit d0a675fde6
9 changed files with 94 additions and 88 deletions

View File

@ -19,6 +19,14 @@ describe("TableCellMargin", () => {
},
},
},
{
"w:start": {
_attr: {
"w:type": "dxa",
"w:w": 0,
},
},
},
{
"w:bottom": {
_attr: {
@ -35,14 +43,6 @@ describe("TableCellMargin", () => {
},
},
},
{
"w:start": {
_attr: {
"w:type": "dxa",
"w:w": 0,
},
},
},
],
});
});
@ -65,6 +65,14 @@ describe("TableCellMargin", () => {
},
},
},
{
"w:start": {
_attr: {
"w:type": "dxa",
"w:w": 5,
},
},
},
{
"w:bottom": {
_attr: {
@ -81,14 +89,6 @@ describe("TableCellMargin", () => {
},
},
},
{
"w:start": {
_attr: {
"w:type": "dxa",
"w:w": 5,
},
},
},
],
});
});

View File

@ -14,8 +14,8 @@ export class TableCellMargin extends XmlComponent {
constructor({ top = 0, left = 0, right = 0, bottom = 0 }: ITableCellMarginOptions) {
super("w:tcMar");
this.root.push(new TopCellMargin(top));
this.root.push(new LeftCellMargin(left));
this.root.push(new BottomCellMargin(bottom));
this.root.push(new RightCellMargin(right));
this.root.push(new LeftCellMargin(left));
}
}

View File

@ -90,6 +90,14 @@ describe("TableCellProperties", () => {
},
},
},
{
"w:start": {
_attr: {
"w:type": "dxa",
"w:w": 0,
},
},
},
{
"w:bottom": {
_attr: {
@ -106,14 +114,6 @@ describe("TableCellProperties", () => {
},
},
},
{
"w:start": {
_attr: {
"w:type": "dxa",
"w:w": 0,
},
},
},
],
},
],

View File

@ -21,7 +21,6 @@ export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
constructor() {
super("w:tcPr");
this.cellBorder = new TableCellBorders();
this.root.push(this.cellBorder);
}
public get Borders(): TableCellBorders {
@ -69,4 +68,10 @@ export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
return this;
}
public addBorders(): TableCellProperties {
this.root.push(this.cellBorder);
return this;
}
}

View File

@ -354,6 +354,14 @@ describe("TableCell", () => {
},
},
},
{
"w:start": {
_attr: {
"w:type": "dxa",
"w:w": 1,
},
},
},
{
"w:bottom": {
_attr: {
@ -370,14 +378,6 @@ describe("TableCell", () => {
},
},
},
{
"w:start": {
_attr: {
"w:type": "dxa",
"w:w": 1,
},
},
},
],
},
],

View File

@ -57,12 +57,12 @@ export class TableCell extends XmlComponent {
this.root.push(child);
}
if (options.verticalAlign) {
properties.setVerticalAlign(options.verticalAlign);
if (options.width) {
properties.setWidth(options.width.size, options.width.type);
}
if (options.textDirection) {
properties.setTextDirection(options.textDirection);
if (options.columnSpan) {
properties.addGridSpan(options.columnSpan);
}
if (options.verticalMerge) {
@ -72,23 +72,8 @@ export class TableCell extends XmlComponent {
properties.addVerticalMerge(VerticalMergeType.RESTART);
}
if (options.margins) {
properties.addMargins(options.margins);
}
if (options.shading) {
properties.setShading(options.shading);
}
if (options.columnSpan) {
properties.addGridSpan(options.columnSpan);
}
if (options.width) {
properties.setWidth(options.width.size, options.width.type);
}
if (options.borders) {
properties.addBorders();
if (options.borders.top) {
properties.Borders.addTopBorder(options.borders.top.style, options.borders.top.size, options.borders.top.color);
}
@ -102,6 +87,22 @@ export class TableCell extends XmlComponent {
properties.Borders.addRightBorder(options.borders.right.style, options.borders.right.size, options.borders.right.color);
}
}
if (options.shading) {
properties.setShading(options.shading);
}
if (options.margins) {
properties.addMargins(options.margins);
}
if (options.textDirection) {
properties.setTextDirection(options.textDirection);
}
if (options.verticalAlign) {
properties.setVerticalAlign(options.verticalAlign);
}
}
public prepForXml(context: IContext): IXmlableObject | undefined {