2017-03-10 16:51:19 +01:00
|
|
|
import { XmlAttributeComponent, XmlComponent } from "../xml-components";
|
2017-03-07 19:22:10 +01:00
|
|
|
|
2017-03-10 18:54:35 +01:00
|
|
|
export type widthTypes = "dxa" | "pct" | "nil" | "auto";
|
2017-03-07 19:22:10 +01:00
|
|
|
|
2017-03-10 16:51:19 +01:00
|
|
|
export class TableProperties extends XmlComponent {
|
2017-03-07 19:22:10 +01:00
|
|
|
constructor() {
|
2017-03-10 16:51:19 +01:00
|
|
|
super("w:tblPr");
|
2017-03-07 19:22:10 +01:00
|
|
|
}
|
|
|
|
|
2017-03-10 16:51:19 +01:00
|
|
|
public setWidth(type: widthTypes, w: number | string): TableProperties {
|
|
|
|
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
|
|
|
|
|
|
|
public fixedWidthLayout(): TableProperties {
|
|
|
|
this.root.push(new TableLayout("fixed"));
|
|
|
|
return this;
|
|
|
|
}
|
2017-03-07 19:22:10 +01:00
|
|
|
}
|
|
|
|
|
2017-03-10 16:51:19 +01:00
|
|
|
interface ITableWidth {
|
|
|
|
type: widthTypes;
|
|
|
|
w: number | string;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> {
|
|
|
|
protected xmlKeys = {type: "w:type", w: "w:w"};
|
|
|
|
}
|
|
|
|
|
2017-03-07 19:22:10 +01:00
|
|
|
class PreferredTableWidth extends XmlComponent {
|
2017-03-10 16:51:19 +01:00
|
|
|
constructor(type: widthTypes, w: number | string) {
|
|
|
|
super("w:tblW");
|
|
|
|
this.root.push(new TableWidthAttributes({type, w}));
|
2017-03-07 19:22:10 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-11 09:59:29 +01:00
|
|
|
|
|
|
|
type tableLayout = "autofit" | "fixed";
|
|
|
|
|
|
|
|
class TableLayoutAttributes extends XmlAttributeComponent<{type: tableLayout}> {
|
|
|
|
protected xmlKeys = {type: "w:type"};
|
|
|
|
}
|
|
|
|
|
|
|
|
class TableLayout extends XmlComponent {
|
|
|
|
constructor(type: tableLayout) {
|
|
|
|
super("w:tblLayout");
|
|
|
|
this.root.push(new TableLayoutAttributes({type}));
|
|
|
|
}
|
|
|
|
}
|