2018-08-23 00:55:33 +01:00
|
|
|
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
2018-10-23 23:44:50 +01:00
|
|
|
|
|
|
|
import { WidthType } from "../table-cell";
|
2018-08-23 00:55:33 +01:00
|
|
|
|
2018-11-02 02:51:57 +00:00
|
|
|
class TableCellMarginAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly value: number }> {
|
2019-04-08 13:50:40 -04:00
|
|
|
protected readonly xmlKeys = { value: "w:w", type: "w:type" };
|
2018-08-23 00:55:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class BaseTableCellMargin extends XmlComponent {
|
|
|
|
public setProperties(value: number, type: WidthType = WidthType.DXA): void {
|
|
|
|
this.root.push(
|
|
|
|
new TableCellMarginAttributes({
|
|
|
|
type: type,
|
|
|
|
value: value,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class TableCellMargin extends XmlComponent {
|
|
|
|
constructor() {
|
|
|
|
super("w:tblCellMar");
|
|
|
|
}
|
|
|
|
|
2018-09-20 00:41:57 +01:00
|
|
|
public prepForXml(): IXmlableObject | undefined {
|
|
|
|
if (this.root.length > 0) {
|
|
|
|
return super.prepForXml();
|
|
|
|
}
|
2018-08-23 00:55:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public addTopMargin(value: number, type: WidthType = WidthType.DXA): void {
|
|
|
|
const top = new BaseTableCellMargin("w:top");
|
|
|
|
|
|
|
|
top.setProperties(value, type);
|
|
|
|
this.root.push(top);
|
|
|
|
}
|
|
|
|
|
|
|
|
public addLeftMargin(value: number, type: WidthType = WidthType.DXA): void {
|
|
|
|
const left = new BaseTableCellMargin("w:left");
|
|
|
|
|
|
|
|
left.setProperties(value, type);
|
|
|
|
this.root.push(left);
|
|
|
|
}
|
|
|
|
|
|
|
|
public addBottomMargin(value: number, type: WidthType = WidthType.DXA): void {
|
|
|
|
const bottom = new BaseTableCellMargin("w:bottom");
|
|
|
|
|
|
|
|
bottom.setProperties(value, type);
|
|
|
|
this.root.push(bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
public addRightMargin(value: number, type: WidthType = WidthType.DXA): void {
|
|
|
|
const right = new BaseTableCellMargin("w:right");
|
|
|
|
|
|
|
|
right.setProperties(value, type);
|
|
|
|
this.root.push(right);
|
|
|
|
}
|
|
|
|
}
|