added fixedWidthLayout option and method
This commit is contained in:
@ -55,6 +55,11 @@ export class Table extends XmlComponent {
|
||||
this.properties.setWidth(type, width);
|
||||
return this;
|
||||
}
|
||||
|
||||
public fixedWidthLayout(): Table {
|
||||
this.properties.fixedWidthLayout();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
class TableRow extends XmlComponent {
|
||||
|
@ -11,6 +11,11 @@ export class TableProperties extends XmlComponent {
|
||||
this.root.push(new PreferredTableWidth(type, w));
|
||||
return this;
|
||||
}
|
||||
|
||||
public fixedWidthLayout(): TableProperties {
|
||||
this.root.push(new TableLayout("fixed"));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
interface ITableWidth {
|
||||
@ -28,3 +33,16 @@ class PreferredTableWidth extends XmlComponent {
|
||||
this.root.push(new TableWidthAttributes({type, w}));
|
||||
}
|
||||
}
|
||||
|
||||
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}));
|
||||
}
|
||||
}
|
||||
|
@ -22,4 +22,16 @@ describe("TableProperties", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#fixedWidthLayout", () => {
|
||||
it("sets the table to fixed width layout", () => {
|
||||
const tp = new TableProperties().fixedWidthLayout();
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblPr": [
|
||||
{"w:tblLayout": [{_attr: {"w:type": "fixed"}}]},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -93,4 +93,17 @@ describe("Table", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#fixedWidthLayout", () => {
|
||||
it("sets the table to fixed width layout", () => {
|
||||
const table = new Table(2, 2).fixedWidthLayout();
|
||||
const tree = new Formatter().format(table);
|
||||
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1);
|
||||
expect(tree["w:tbl"][0]).to.deep.equal({
|
||||
"w:tblPr": [
|
||||
{"w:tblLayout": [{_attr: {"w:type": "fixed"}}]},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user