2017-12-30 20:25:16 +00:00
|
|
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
2018-08-23 00:55:33 +01:00
|
|
|
import { WidthType } from "./table-cell";
|
|
|
|
import { TableCellMargin } from "./table-cell-margin";
|
2017-03-07 19:22:10 +01:00
|
|
|
|
2017-03-10 16:51:19 +01:00
|
|
|
export class TableProperties extends XmlComponent {
|
2018-08-23 00:55:33 +01:00
|
|
|
private readonly cellMargain: TableCellMargin;
|
|
|
|
|
2017-03-07 19:22:10 +01:00
|
|
|
constructor() {
|
2017-03-10 16:51:19 +01:00
|
|
|
super("w:tblPr");
|
2018-08-23 00:55:33 +01:00
|
|
|
|
|
|
|
this.cellMargain = new TableCellMargin();
|
|
|
|
this.root.push(this.cellMargain);
|
2017-03-07 19:22:10 +01:00
|
|
|
}
|
|
|
|
|
2018-08-23 00:55:33 +01:00
|
|
|
public setWidth(type: WidthType, w: number | string): TableProperties {
|
2017-03-10 16:51:19 +01:00
|
|
|
this.root.push(new PreferredTableWidth(type, w));
|
|
|
|
return this;
|
2017-03-07 19:22:10 +01:00
|
|
|
}
|
2017-03-11 09:59:29 +01:00
|
|
|
|
2018-08-07 01:25:28 +01:00
|
|
|
public setFixedWidthLayout(): TableProperties {
|
2017-03-11 09:59:29 +01:00
|
|
|
this.root.push(new TableLayout("fixed"));
|
|
|
|
return this;
|
|
|
|
}
|
2018-03-22 23:04:46 +00:00
|
|
|
|
|
|
|
public setBorder(): TableProperties {
|
|
|
|
this.root.push(new TableBorders());
|
|
|
|
return this;
|
|
|
|
}
|
2018-08-23 00:55:33 +01:00
|
|
|
|
|
|
|
public get CellMargin(): TableCellMargin {
|
|
|
|
return this.cellMargain;
|
|
|
|
}
|
2017-03-07 19:22:10 +01:00
|
|
|
}
|
|
|
|
|
2017-03-10 16:51:19 +01:00
|
|
|
interface ITableWidth {
|
2018-08-23 00:55:33 +01:00
|
|
|
type: WidthType;
|
2017-03-10 16:51:19 +01:00
|
|
|
w: number | string;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> {
|
2018-01-23 01:33:12 +00:00
|
|
|
protected xmlKeys = { type: "w:type", w: "w:w" };
|
2017-03-10 16:51:19 +01:00
|
|
|
}
|
|
|
|
|
2017-03-07 19:22:10 +01:00
|
|
|
class PreferredTableWidth extends XmlComponent {
|
2018-08-23 00:55:33 +01:00
|
|
|
constructor(type: WidthType, w: number | string) {
|
2017-03-10 16:51:19 +01:00
|
|
|
super("w:tblW");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(new TableWidthAttributes({ type, w }));
|
2017-03-07 19:22:10 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-11 09:59:29 +01:00
|
|
|
|
2017-07-07 14:31:08 +01:00
|
|
|
type TableLayoutOptions = "autofit" | "fixed";
|
2017-03-11 09:59:29 +01:00
|
|
|
|
2018-01-23 01:33:12 +00:00
|
|
|
class TableLayoutAttributes extends XmlAttributeComponent<{ type: TableLayoutOptions }> {
|
|
|
|
protected xmlKeys = { type: "w:type" };
|
2017-03-11 09:59:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class TableLayout extends XmlComponent {
|
2017-07-07 14:31:08 +01:00
|
|
|
constructor(type: TableLayoutOptions) {
|
2017-03-11 09:59:29 +01:00
|
|
|
super("w:tblLayout");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(new TableLayoutAttributes({ type }));
|
2017-03-11 09:59:29 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-22 22:55:33 +00:00
|
|
|
|
|
|
|
class TableBorders extends XmlComponent {
|
|
|
|
constructor() {
|
|
|
|
super("w:tblBorders");
|
|
|
|
this.root.push(new TableBordersElement("w:top", "single", 4, 0, "auto"));
|
|
|
|
this.root.push(new TableBordersElement("w:left", "single", 4, 0, "auto"));
|
|
|
|
this.root.push(new TableBordersElement("w:bottom", "single", 4, 0, "auto"));
|
|
|
|
this.root.push(new TableBordersElement("w:right", "single", 4, 0, "auto"));
|
|
|
|
this.root.push(new TableBordersElement("w:insideH", "single", 4, 0, "auto"));
|
|
|
|
this.root.push(new TableBordersElement("w:insideV", "single", 4, 0, "auto"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TableBordersElement extends XmlComponent {
|
|
|
|
constructor(elementName: string, value: string, size: number, space: number, color: string) {
|
|
|
|
super(elementName);
|
|
|
|
this.root.push(
|
|
|
|
new TableBordersAttributes({
|
|
|
|
value,
|
|
|
|
size,
|
|
|
|
space,
|
|
|
|
color,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TableBordersAttributes extends XmlAttributeComponent<{ value: string; size: number; space: number; color: string }> {
|
|
|
|
protected xmlKeys = {
|
|
|
|
value: "w:val",
|
|
|
|
size: "w:sz",
|
|
|
|
space: "w:space",
|
|
|
|
color: "w:color",
|
|
|
|
};
|
|
|
|
}
|