Files
docx-js/src/file/table/table-row/table-row-properties.ts
Bruce Duncan 816cb54b14 Optimize XML output by properly constructing objects to send to the xml library so that it can produce proper empty elements.
Rework the way attributes are stored in ImportedXmlComponent to match elsewhere (required allowing for a null xmlKeys in the XmlAttributeComponent interface).
Rework the way paragraphs get added to the end of table cells if needed.
The goal in both reworks is to not mess around with the objects output from `prepForXml` if we can avoid it.
Made the output of RunProperties, ParagraphProperties, TableCellProperties, TableRowProperties, and TableProperties all optional based on whether they contain any attributes or children.  Changed code in PageBorders, TableCellMargin, and TableCellBorders that implemented this same thing by overriding `prepForXml` so that it uses the new XmlComponent subclass instead.
Removed commented out code that attempted to fix-up XML output and make proper empty elements.
Fixed all affected tests.
Turn off `no-null-keyword` in the linter as we need to use null to signal to the `xml` library to create an empty element with no attributes (`undefined` will not work in its place).

Fixes #306
2019-04-09 05:27:18 -04:00

42 lines
1.1 KiB
TypeScript

import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
export class TableRowProperties extends IgnoreIfEmptyXmlComponent {
constructor() {
super("w:trPr");
}
public setCantSplit(): TableRowProperties {
this.root.push(new CantSplit());
return this;
}
public setTableHeader(): TableRowProperties {
this.root.push(new TableHeader());
return this;
}
}
class CantSplitAttributes extends XmlAttributeComponent<{ readonly val: boolean }> {
protected readonly xmlKeys = { val: "w:val" };
}
export class CantSplit extends XmlComponent {
constructor() {
super("w:cantSplit");
this.root.push(new CantSplitAttributes({ val: true }));
}
}
class TableHeaderAttributes extends XmlAttributeComponent<{ readonly val: boolean }> {
protected readonly xmlKeys = { val: "w:val" };
}
export class TableHeader extends XmlComponent {
constructor() {
super("w:tblHeader");
this.root.push(new TableHeaderAttributes({ val: true }));
}
}