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
This commit is contained in:
@ -10,14 +10,14 @@ describe("GridCol", () => {
|
||||
const grid = new GridCol(1234);
|
||||
const tree = new Formatter().format(grid);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:gridCol": [{ _attr: { "w:w": 1234 } }],
|
||||
"w:gridCol": { _attr: { "w:w": 1234 } },
|
||||
});
|
||||
});
|
||||
|
||||
it("does not set a width attribute if not given", () => {
|
||||
const grid = new GridCol();
|
||||
const tree = new Formatter().format(grid);
|
||||
expect(tree).to.deep.equal({ "w:gridCol": [] });
|
||||
expect(tree).to.deep.equal({ "w:gridCol": null });
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -29,9 +29,9 @@ describe("TableGrid", () => {
|
||||
const tree = new Formatter().format(grid);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblGrid": [
|
||||
{ "w:gridCol": [{ _attr: { "w:w": 1234 } }] },
|
||||
{ "w:gridCol": [{ _attr: { "w:w": 321 } }] },
|
||||
{ "w:gridCol": [{ _attr: { "w:w": 123 } }] },
|
||||
{ "w:gridCol": { _attr: { "w:w": 1234 } } },
|
||||
{ "w:gridCol": { _attr: { "w:w": 321 } } },
|
||||
{ "w:gridCol": { _attr: { "w:w": 123 } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
@ -7,30 +7,26 @@ import { ShadingType, TableShading } from "./shading";
|
||||
describe("TableShading", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should create", () => {
|
||||
const cellMargain = new TableShading({});
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
const shading = new TableShading({});
|
||||
const tree = new Formatter().format(shading);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:shd": [
|
||||
{
|
||||
_attr: {},
|
||||
},
|
||||
],
|
||||
"w:shd": {
|
||||
_attr: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("should create with params", () => {
|
||||
const cellMargain = new TableShading({ val: ShadingType.PERCENT_40, color: "FF0000", fill: "555555" });
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
const shading = new TableShading({ val: ShadingType.PERCENT_40, color: "FF0000", fill: "555555" });
|
||||
const tree = new Formatter().format(shading);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:shd": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF0000",
|
||||
"w:fill": "555555",
|
||||
"w:val": "pct40",
|
||||
},
|
||||
"w:shd": {
|
||||
_attr: {
|
||||
"w:color": "FF0000",
|
||||
"w:fill": "555555",
|
||||
"w:val": "pct40",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -10,14 +10,12 @@ describe("TopCellMargain", () => {
|
||||
const cellMargain = new TopCellMargain(1);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:top": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -29,14 +27,12 @@ describe("BottomCellMargain", () => {
|
||||
const cellMargain = new BottomCellMargain(1);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:bottom": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -48,14 +44,12 @@ describe("LeftCellMargain", () => {
|
||||
const cellMargain = new LeftCellMargain(1);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:start": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
"w:start": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -67,14 +61,12 @@ describe("RightCellMargain", () => {
|
||||
const cellMargain = new RightCellMargain(1);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:end": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
"w:end": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -12,44 +12,36 @@ describe("TableCellMargain", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcMar": [
|
||||
{
|
||||
"w:top": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:end": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
"w:end": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:start": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
"w:start": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -66,44 +58,36 @@ describe("TableCellMargain", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcMar": [
|
||||
{
|
||||
"w:top": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:end": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
"w:end": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:start": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
"w:start": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { BorderStyle } from "file/styles";
|
||||
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
interface ICellBorder {
|
||||
readonly style: BorderStyle;
|
||||
@ -24,17 +24,11 @@ class BaseTableCellBorder extends XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
export class TableCellBorders extends XmlComponent {
|
||||
export class TableCellBorders extends IgnoreIfEmptyXmlComponent {
|
||||
constructor() {
|
||||
super("w:tcBorders");
|
||||
}
|
||||
|
||||
public prepForXml(): IXmlableObject | undefined {
|
||||
if (this.root.length > 0) {
|
||||
return super.prepForXml();
|
||||
}
|
||||
}
|
||||
|
||||
public addTopBorder(style: BorderStyle, size: number, color: string): TableCellBorders {
|
||||
const top = new BaseTableCellBorder("w:top");
|
||||
top.setProperties(style, size, color);
|
||||
|
@ -9,77 +9,80 @@ import { TableCellProperties } from "./table-cell-properties";
|
||||
describe("TableCellProperties", () => {
|
||||
describe("#constructor", () => {
|
||||
it("creates an initially empty property object", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [] });
|
||||
const properties = new TableCellProperties();
|
||||
// The TableCellProperties is ignorable if there are no attributes,
|
||||
// which results in prepForXml returning undefined, which causes
|
||||
// the formatter to throw an error if that is the only object it
|
||||
// has been asked to format.
|
||||
expect(() => new Formatter().format(properties)).to.throw("XMLComponent did not format correctly");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addGridSpan", () => {
|
||||
it("adds grid span", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.addGridSpan(1);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:gridSpan": [{ _attr: { "w:val": 1 } }] }] });
|
||||
const properties = new TableCellProperties();
|
||||
properties.addGridSpan(1);
|
||||
const tree = new Formatter().format(properties);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:gridSpan": { _attr: { "w:val": 1 } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addVerticalMerge", () => {
|
||||
it("adds vertical merge", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.addVerticalMerge(VMergeType.CONTINUE);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vMerge": [{ _attr: { "w:val": "continue" } }] }] });
|
||||
const properties = new TableCellProperties();
|
||||
properties.addVerticalMerge(VMergeType.CONTINUE);
|
||||
const tree = new Formatter().format(properties);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setVerticalAlign", () => {
|
||||
it("sets vertical align", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.setVerticalAlign(VerticalAlign.BOTTOM);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vAlign": [{ _attr: { "w:val": "bottom" } }] }] });
|
||||
const properties = new TableCellProperties();
|
||||
properties.setVerticalAlign(VerticalAlign.BOTTOM);
|
||||
const tree = new Formatter().format(properties);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vAlign": { _attr: { "w:val": "bottom" } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setWidth", () => {
|
||||
it("should set width", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.setWidth(1, WidthType.DXA);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": [{ _attr: { "w:type": "dxa", "w:w": 1 } }] }] });
|
||||
const properties = new TableCellProperties();
|
||||
properties.setWidth(1, WidthType.DXA);
|
||||
const tree = new Formatter().format(properties);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": { _attr: { "w:type": "dxa", "w:w": 1 } } }] });
|
||||
});
|
||||
|
||||
it("should set width using default of AUTO", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.setWidth(1);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": [{ _attr: { "w:type": "auto", "w:w": 1 } }] }] });
|
||||
const properties = new TableCellProperties();
|
||||
properties.setWidth(1);
|
||||
const tree = new Formatter().format(properties);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": { _attr: { "w:type": "auto", "w:w": 1 } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setShading", () => {
|
||||
it("sets shading", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.setShading({
|
||||
const properties = new TableCellProperties();
|
||||
properties.setShading({
|
||||
fill: "test",
|
||||
color: "000",
|
||||
});
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:shd": [{ _attr: { "w:fill": "test", "w:color": "000" } }] }] });
|
||||
const tree = new Formatter().format(properties);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:shd": { _attr: { "w:fill": "test", "w:color": "000" } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#Borders", () => {
|
||||
it("should return the TableCellBorders if Border has borders", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red");
|
||||
const borders = cellMargain.Borders;
|
||||
const properties = new TableCellProperties();
|
||||
properties.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red");
|
||||
const borders = properties.Borders;
|
||||
|
||||
const tree = new Formatter().format(borders);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcBorders": [{ "w:top": [{ _attr: { "w:val": "dashDotStroked", "w:sz": 3, "w:color": "red" } }] }],
|
||||
"w:tcBorders": [{ "w:top": { _attr: { "w:val": "dashDotStroked", "w:sz": 3, "w:color": "red" } } }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
|
||||
|
||||
import { ITableShadingAttributesProperties, TableShading } from "../shading";
|
||||
import { ITableCellMargainOptions, TableCellMargain } from "./cell-margain/table-cell-margains";
|
||||
import { GridSpan, TableCellBorders, TableCellWidth, VAlign, VerticalAlign, VMerge, VMergeType, WidthType } from "./table-cell-components";
|
||||
|
||||
export class TableCellProperties extends XmlComponent {
|
||||
export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
|
||||
private readonly cellBorder: TableCellBorders;
|
||||
|
||||
constructor() {
|
||||
|
@ -22,15 +22,13 @@ describe("TableCellBorders", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcBorders": [
|
||||
{
|
||||
"w:top": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 1,
|
||||
"w:val": "dotted",
|
||||
},
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 1,
|
||||
"w:val": "dotted",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -44,15 +42,13 @@ describe("TableCellBorders", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcBorders": [
|
||||
{
|
||||
"w:start": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 2,
|
||||
"w:val": "single",
|
||||
},
|
||||
"w:start": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 2,
|
||||
"w:val": "single",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -66,15 +62,13 @@ describe("TableCellBorders", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcBorders": [
|
||||
{
|
||||
"w:bottom": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -88,15 +82,13 @@ describe("TableCellBorders", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcBorders": [
|
||||
{
|
||||
"w:end": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 3,
|
||||
"w:val": "thick",
|
||||
},
|
||||
"w:end": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 3,
|
||||
"w:val": "thick",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -110,15 +102,13 @@ describe("TableCellBorders", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcBorders": [
|
||||
{
|
||||
"w:left": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 3,
|
||||
"w:val": "thick",
|
||||
},
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 3,
|
||||
"w:val": "thick",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -132,15 +122,13 @@ describe("TableCellBorders", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcBorders": [
|
||||
{
|
||||
"w:right": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 3,
|
||||
"w:val": "thick",
|
||||
},
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 3,
|
||||
"w:val": "thick",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -159,70 +147,58 @@ describe("TableCellBorders", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcBorders": [
|
||||
{
|
||||
"w:top": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 1,
|
||||
"w:val": "dotted",
|
||||
},
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 1,
|
||||
"w:val": "dotted",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:end": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 3,
|
||||
"w:val": "thick",
|
||||
},
|
||||
"w:end": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 3,
|
||||
"w:val": "thick",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:start": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 2,
|
||||
"w:val": "single",
|
||||
},
|
||||
"w:start": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 2,
|
||||
"w:val": "single",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:left": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 2,
|
||||
"w:val": "single",
|
||||
},
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 2,
|
||||
"w:val": "single",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 2,
|
||||
"w:val": "single",
|
||||
},
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "FF00FF",
|
||||
"w:sz": 2,
|
||||
"w:val": "single",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -236,14 +212,12 @@ describe("TableCellWidth", () => {
|
||||
const tcWidth = new TableCellWidth(100, WidthType.DXA);
|
||||
const tree = new Formatter().format(tcWidth);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcW": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 100,
|
||||
},
|
||||
"w:tcW": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 100,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -30,16 +30,10 @@ export class TableCell extends XmlComponent {
|
||||
|
||||
public prepForXml(): IXmlableObject | undefined {
|
||||
// Cells must end with a paragraph
|
||||
const retval = super.prepForXml();
|
||||
if (!retval) {
|
||||
return undefined;
|
||||
if (!(this.root[this.root.length - 1] instanceof Paragraph)) {
|
||||
this.createParagraph();
|
||||
}
|
||||
|
||||
const content = retval["w:tc"];
|
||||
if (!content[content.length - 1]["w:p"]) {
|
||||
content.push(new Paragraph().prepForXml());
|
||||
}
|
||||
return retval;
|
||||
return super.prepForXml();
|
||||
}
|
||||
|
||||
public createParagraph(text?: string): Paragraph {
|
||||
|
@ -37,15 +37,15 @@ describe("TableColumn", () => {
|
||||
|
||||
const tree = new Formatter().format(cells[0]);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tc": [{ "w:tcPr": [{ "w:vMerge": [{ _attr: { "w:val": "restart" } }] }] }, { "w:p": [{ "w:pPr": [] }] }],
|
||||
"w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "restart" } } }] }, { "w:p": null }],
|
||||
});
|
||||
|
||||
const tree2 = new Formatter().format(cells[1]);
|
||||
expect(tree2).to.deep.equal({ "w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }] });
|
||||
expect(tree2).to.deep.equal({ "w:tc": [{ "w:p": null }] });
|
||||
|
||||
const tree3 = new Formatter().format(cells[2]);
|
||||
expect(tree3).to.deep.equal({
|
||||
"w:tc": [{ "w:tcPr": [{ "w:vMerge": [{ _attr: { "w:val": "continue" } }] }] }, { "w:p": [{ "w:pPr": [] }] }],
|
||||
"w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] }, { "w:p": null }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ describe("TableCellMargin", () => {
|
||||
const cellMargain = new TableCellMargin();
|
||||
cellMargain.addTopMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }] });
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
@ -27,7 +27,7 @@ describe("TableCellMargin", () => {
|
||||
const cellMargain = new TableCellMargin();
|
||||
cellMargain.addLeftMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }] });
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
@ -36,7 +36,7 @@ describe("TableCellMargin", () => {
|
||||
const cellMargain = new TableCellMargin();
|
||||
cellMargain.addBottomMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }] });
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
@ -45,7 +45,7 @@ describe("TableCellMargin", () => {
|
||||
const cellMargain = new TableCellMargin();
|
||||
cellMargain.addRightMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }] });
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
import { WidthType } from "../table-cell";
|
||||
|
||||
@ -17,17 +17,11 @@ class BaseTableCellMargin extends XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
export class TableCellMargin extends XmlComponent {
|
||||
export class TableCellMargin extends IgnoreIfEmptyXmlComponent {
|
||||
constructor() {
|
||||
super("w:tblCellMar");
|
||||
}
|
||||
|
||||
public prepForXml(): IXmlableObject | undefined {
|
||||
if (this.root.length > 0) {
|
||||
return super.prepForXml();
|
||||
}
|
||||
}
|
||||
|
||||
public addTopMargin(value: number, type: WidthType = WidthType.DXA): void {
|
||||
const top = new BaseTableCellMargin("w:top");
|
||||
|
||||
|
@ -26,20 +26,18 @@ describe("Table Float Properties", () => {
|
||||
});
|
||||
|
||||
const DEFAULT_TFP = {
|
||||
"w:tblpPr": [
|
||||
{
|
||||
_attr: {
|
||||
"w:horzAnchor": "margin",
|
||||
"w:vertAnchor": "page",
|
||||
"w:tblpX": 10,
|
||||
"w:tblpXSpec": "center",
|
||||
"w:tblpY": 20,
|
||||
"w:tblpYSpec": "bottom",
|
||||
"w:bottomFromText": 30,
|
||||
"w:topFromText": 40,
|
||||
"w:leftFromText": 50,
|
||||
"w:rightFromText": 60,
|
||||
},
|
||||
"w:tblpPr": {
|
||||
_attr: {
|
||||
"w:horzAnchor": "margin",
|
||||
"w:vertAnchor": "page",
|
||||
"w:tblpX": 10,
|
||||
"w:tblpXSpec": "center",
|
||||
"w:tblpY": 20,
|
||||
"w:tblpYSpec": "bottom",
|
||||
"w:bottomFromText": 30,
|
||||
"w:topFromText": 40,
|
||||
"w:leftFromText": 50,
|
||||
"w:rightFromText": 60,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
@ -9,8 +9,11 @@ describe("TableProperties", () => {
|
||||
describe("#constructor", () => {
|
||||
it("creates an initially empty property object", () => {
|
||||
const tp = new TableProperties();
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({ "w:tblPr": [] });
|
||||
// The TableProperties is ignorable if there are no attributes,
|
||||
// which results in prepForXml returning undefined, which causes
|
||||
// the formatter to throw an error if that is the only object it
|
||||
// has been asked to format.
|
||||
expect(() => new Formatter().format(tp)).to.throw("XMLComponent did not format correctly");
|
||||
});
|
||||
});
|
||||
|
||||
@ -19,7 +22,7 @@ describe("TableProperties", () => {
|
||||
const tp = new TableProperties().setWidth(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }],
|
||||
"w:tblPr": [{ "w:tblW": { _attr: { "w:type": "dxa", "w:w": 1234 } } }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -27,7 +30,7 @@ describe("TableProperties", () => {
|
||||
const tp = new TableProperties().setWidth(1234);
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "auto", "w:w": 1234 } }] }],
|
||||
"w:tblPr": [{ "w:tblW": { _attr: { "w:type": "auto", "w:w": 1234 } } }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -37,7 +40,7 @@ describe("TableProperties", () => {
|
||||
const tp = new TableProperties().setFixedWidthLayout();
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],
|
||||
"w:tblPr": [{ "w:tblLayout": { _attr: { "w:type": "fixed" } } }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -48,7 +51,7 @@ describe("TableProperties", () => {
|
||||
tp.CellMargin.addTopMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblPr": [{ "w:tblCellMar": [{ "w:top": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }] }],
|
||||
"w:tblPr": [{ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -57,7 +60,7 @@ describe("TableProperties", () => {
|
||||
tp.CellMargin.addLeftMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblPr": [{ "w:tblCellMar": [{ "w:left": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }] }],
|
||||
"w:tblPr": [{ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
|
||||
|
||||
import { ITableShadingAttributesProperties, TableShading } from "../shading";
|
||||
import { WidthType } from "../table-cell";
|
||||
@ -8,7 +8,7 @@ import { ITableFloatOptions, TableFloatProperties } from "./table-float-properti
|
||||
import { TableLayout, TableLayoutType } from "./table-layout";
|
||||
import { PreferredTableWidth } from "./table-width";
|
||||
|
||||
export class TableProperties extends XmlComponent {
|
||||
export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
||||
private readonly cellMargin: TableCellMargin;
|
||||
|
||||
constructor() {
|
||||
|
@ -6,8 +6,11 @@ describe("TableRowProperties", () => {
|
||||
describe("#constructor", () => {
|
||||
it("creates an initially empty property object", () => {
|
||||
const rowProperties = new TableRowProperties();
|
||||
const tree = new Formatter().format(rowProperties);
|
||||
expect(tree).to.deep.equal({ "w:trPr": [] });
|
||||
// The TableRowProperties is ignorable if there are no attributes,
|
||||
// which results in prepForXml returning undefined, which causes
|
||||
// the formatter to throw an error if that is the only object it
|
||||
// has been asked to format.
|
||||
expect(() => new Formatter().format(rowProperties)).to.throw("XMLComponent did not format correctly");
|
||||
});
|
||||
});
|
||||
|
||||
@ -16,7 +19,7 @@ describe("TableRowProperties", () => {
|
||||
const rowProperties = new TableRowProperties();
|
||||
rowProperties.setCantSplit();
|
||||
const tree = new Formatter().format(rowProperties);
|
||||
expect(tree).to.deep.equal({ "w:trPr": [{ "w:cantSplit": [{ _attr: { "w:val": true } }] }] });
|
||||
expect(tree).to.deep.equal({ "w:trPr": [{ "w:cantSplit": { _attr: { "w:val": true } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
@ -25,7 +28,7 @@ describe("TableRowProperties", () => {
|
||||
const rowProperties = new TableRowProperties();
|
||||
rowProperties.setTableHeader();
|
||||
const tree = new Formatter().format(rowProperties);
|
||||
expect(tree).to.deep.equal({ "w:trPr": [{ "w:tblHeader": [{ _attr: { "w:val": true } }] }] });
|
||||
expect(tree).to.deep.equal({ "w:trPr": [{ "w:tblHeader": { _attr: { "w:val": true } } }] });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export class TableRowProperties extends XmlComponent {
|
||||
export class TableRowProperties extends IgnoreIfEmptyXmlComponent {
|
||||
constructor() {
|
||||
super("w:trPr");
|
||||
}
|
||||
|
@ -11,11 +11,7 @@ describe("TableRow", () => {
|
||||
const tableRow = new TableRow([]);
|
||||
const tree = new Formatter().format(tableRow);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tr": [
|
||||
{
|
||||
"w:trPr": [],
|
||||
},
|
||||
],
|
||||
"w:tr": null,
|
||||
});
|
||||
});
|
||||
|
||||
@ -24,20 +20,10 @@ describe("TableRow", () => {
|
||||
const tree = new Formatter().format(tableRow);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tr": [
|
||||
{
|
||||
"w:trPr": [],
|
||||
},
|
||||
{
|
||||
"w:tc": [
|
||||
{
|
||||
"w:tcPr": [],
|
||||
},
|
||||
{
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [],
|
||||
},
|
||||
],
|
||||
"w:p": null,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -11,68 +11,58 @@ import { RelativeHorizontalPosition, RelativeVerticalPosition, TableAnchorType }
|
||||
const DEFAULT_TABLE_PROPERTIES = {
|
||||
"w:tblCellMar": [
|
||||
{
|
||||
"w:bottom": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "auto",
|
||||
"w:w": 0,
|
||||
},
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:type": "auto",
|
||||
"w:w": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:top": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "auto",
|
||||
"w:w": 0,
|
||||
},
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:type": "auto",
|
||||
"w:w": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:left": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "auto",
|
||||
"w:w": 0,
|
||||
},
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:type": "auto",
|
||||
"w:w": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "auto",
|
||||
"w:w": 0,
|
||||
},
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:type": "auto",
|
||||
"w:w": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const BORDERS = {
|
||||
"w:tblBorders": [
|
||||
{ "w:top": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
{ "w:left": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
{ "w:bottom": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
{ "w:right": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
{ "w:insideH": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
{ "w:insideV": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
{ "w:top": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
{ "w:left": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
{ "w:bottom": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
{ "w:right": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
{ "w:insideH": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
{ "w:insideV": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
],
|
||||
};
|
||||
|
||||
const WIDTHS = {
|
||||
"w:tblW": [
|
||||
{
|
||||
_attr: {
|
||||
"w:type": "auto",
|
||||
"w:w": 100,
|
||||
},
|
||||
"w:tblW": {
|
||||
_attr: {
|
||||
"w:type": "auto",
|
||||
"w:w": 100,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
// const f = {
|
||||
@ -81,45 +71,43 @@ const WIDTHS = {
|
||||
// "w:tblPr": [
|
||||
// {
|
||||
// "w:tblCellMar": [
|
||||
// { "w:bottom": [{ _attr: { "w:type": "auto", "w:w": 0 } }] },
|
||||
// { "w:top": [{ _attr: { "w:type": "auto", "w:w": 0 } }] },
|
||||
// { "w:left": [{ _attr: { "w:type": "auto", "w:w": 0 } }] },
|
||||
// { "w:right": [{ _attr: { "w:type": "auto", "w:w": 0 } }] },
|
||||
// { "w:bottom": { _attr: { "w:type": "auto", "w:w": 0 } } },
|
||||
// { "w:top": { _attr: { "w:type": "auto", "w:w": 0 } } },
|
||||
// { "w:left": { _attr: { "w:type": "auto", "w:w": 0 } } },
|
||||
// { "w:right": { _attr: { "w:type": "auto", "w:w": 0 } } },
|
||||
// ],
|
||||
// },
|
||||
// {
|
||||
// "w:tblBorders": [
|
||||
// { "w:top": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
// { "w:left": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
// { "w:bottom": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
// { "w:right": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
// { "w:insideH": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
// { "w:insideV": [{ _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } }] },
|
||||
// { "w:top": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
// { "w:left": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
// { "w:bottom": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
// { "w:right": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
// { "w:insideH": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
// { "w:insideV": { _attr: { "w:val": "single", "w:sz": 4, "w:space": 0, "w:color": "auto" } } },
|
||||
// ],
|
||||
// },
|
||||
// { "w:tblW": [{ _attr: { "w:type": "auto", "w:w": 100 } }] },
|
||||
// { "w:tblW": { _attr: { "w:type": "auto", "w:w": 100 } } },
|
||||
// {
|
||||
// "w:tblpPr": [
|
||||
// {
|
||||
// _attr: {
|
||||
// "w:horzAnchor": "margin",
|
||||
// "w:vertAnchor": "page",
|
||||
// "w:tblpX": 10,
|
||||
// "w:tblpXSpec": "center",
|
||||
// "w:tblpY": 20,
|
||||
// "w:tblpYSpec": "bottom",
|
||||
// "w:bottomFromText": 30,
|
||||
// "w:topFromText": 40,
|
||||
// "w:leftFromText": 50,
|
||||
// "w:rightFromText": 60,
|
||||
// },
|
||||
// "w:tblpPr": {
|
||||
// _attr: {
|
||||
// "w:horzAnchor": "margin",
|
||||
// "w:vertAnchor": "page",
|
||||
// "w:tblpX": 10,
|
||||
// "w:tblpXSpec": "center",
|
||||
// "w:tblpY": 20,
|
||||
// "w:tblpYSpec": "bottom",
|
||||
// "w:bottomFromText": 30,
|
||||
// "w:topFromText": 40,
|
||||
// "w:leftFromText": 50,
|
||||
// "w:rightFromText": 60,
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// { "w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 100 } }] }] },
|
||||
// { "w:tr": [{ "w:trPr": [] }, { "w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }] }] },
|
||||
// { "w:tblGrid": [{ "w:gridCol": { _attr: { "w:w": 100 } } }] },
|
||||
// { "w:tr": [{ "w:tc": [{ "w:p": null }] }] },
|
||||
// ],
|
||||
// };
|
||||
|
||||
@ -131,16 +119,16 @@ describe("Table", () => {
|
||||
columns: 2,
|
||||
});
|
||||
const tree = new Formatter().format(table);
|
||||
const cell = { "w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }] };
|
||||
const cell = { "w:tc": [{ "w:p": null }] };
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tbl": [
|
||||
{ "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS] },
|
||||
{
|
||||
"w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 100 } }] }, { "w:gridCol": [{ _attr: { "w:w": 100 } }] }],
|
||||
"w:tblGrid": [{ "w:gridCol": { _attr: { "w:w": 100 } } }, { "w:gridCol": { _attr: { "w:w": 100 } } }],
|
||||
},
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell, cell] },
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell, cell] },
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell, cell] },
|
||||
{ "w:tr": [cell, cell] },
|
||||
{ "w:tr": [cell, cell] },
|
||||
{ "w:tr": [cell, cell] },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -172,9 +160,8 @@ describe("Table", () => {
|
||||
const tree = new Formatter().format(table);
|
||||
const cell = (c) => ({
|
||||
"w:tc": [
|
||||
{ "w:tcPr": [] },
|
||||
{
|
||||
"w:p": [{ "w:pPr": [] }, { "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, c] }] }],
|
||||
"w:p": [{ "w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, c] }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -182,10 +169,10 @@ describe("Table", () => {
|
||||
"w:tbl": [
|
||||
{ "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS] },
|
||||
{
|
||||
"w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 100 } }] }, { "w:gridCol": [{ _attr: { "w:w": 100 } }] }],
|
||||
"w:tblGrid": [{ "w:gridCol": { _attr: { "w:w": 100 } } }, { "w:gridCol": { _attr: { "w:w": 100 } } }],
|
||||
},
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell("A1"), cell("B1")] },
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell("A2"), cell("B2")] },
|
||||
{ "w:tr": [cell("A1"), cell("B1")] },
|
||||
{ "w:tr": [cell("A2"), cell("B2")] },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -222,9 +209,8 @@ describe("Table", () => {
|
||||
const tree = new Formatter().format(table);
|
||||
const cell = (c) => ({
|
||||
"w:tc": [
|
||||
{ "w:tcPr": [] },
|
||||
{
|
||||
"w:p": [{ "w:pPr": [] }, { "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, c] }] }],
|
||||
"w:p": [{ "w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, c] }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -232,10 +218,10 @@ describe("Table", () => {
|
||||
"w:tbl": [
|
||||
{ "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS] },
|
||||
{
|
||||
"w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 100 } }] }, { "w:gridCol": [{ _attr: { "w:w": 100 } }] }],
|
||||
"w:tblGrid": [{ "w:gridCol": { _attr: { "w:w": 100 } } }, { "w:gridCol": { _attr: { "w:w": 100 } } }],
|
||||
},
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell("A1"), cell("B1")] },
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell("A2"), cell("B2")] },
|
||||
{ "w:tr": [cell("A1"), cell("B1")] },
|
||||
{ "w:tr": [cell("A2"), cell("B2")] },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -250,7 +236,7 @@ describe("Table", () => {
|
||||
// .which.is.an("array")
|
||||
// .with.has.length.at.least(1);
|
||||
// expect(tree["w:tbl"][0]).to.deep.equal({
|
||||
// "w:tblPr": [DEFAULT_TABLE_PROPERTIES, { "w:tblW": [{ _attr: { "w:type": "pct", "w:w": "1000%" } }] }],
|
||||
// "w:tblPr": [DEFAULT_TABLE_PROPERTIES, { "w:tblW": { _attr: { "w:type": "pct", "w:w": "1000%" } } }],
|
||||
// });
|
||||
// });
|
||||
|
||||
@ -259,7 +245,7 @@ describe("Table", () => {
|
||||
// const tree = new Formatter().format(table);
|
||||
|
||||
// expect(tree["w:tbl"][0]).to.deep.equal({
|
||||
// "w:tblPr": [DEFAULT_TABLE_PROPERTIES, { "w:tblW": [{ _attr: { "w:type": "auto", "w:w": 1000 } }] }],
|
||||
// "w:tblPr": [DEFAULT_TABLE_PROPERTIES, { "w:tblW": { _attr: { "w:type": "auto", "w:w": 1000 } } }],
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
@ -276,7 +262,7 @@ describe("Table", () => {
|
||||
.which.is.an("array")
|
||||
.with.has.length.at.least(1);
|
||||
expect(tree["w:tbl"][0]).to.deep.equal({
|
||||
"w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS, { "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],
|
||||
"w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS, { "w:tblLayout": { _attr: { "w:type": "fixed" } } }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -298,7 +284,7 @@ describe("Table", () => {
|
||||
.to.be.an("array")
|
||||
.which.has.length.at.least(1);
|
||||
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({
|
||||
"w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }],
|
||||
"w:tc": [{ "w:p": null }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -325,7 +311,7 @@ describe("Table", () => {
|
||||
const cell = row["w:tr"].find((x) => x["w:tc"]);
|
||||
expect(cell).not.to.be.undefined;
|
||||
expect(cell["w:tc"][cell["w:tc"].length - 1]).to.deep.equal({
|
||||
"w:p": [{ "w:pPr": [] }],
|
||||
"w:p": null,
|
||||
});
|
||||
});
|
||||
|
||||
@ -346,12 +332,8 @@ describe("Table", () => {
|
||||
.which.has.length.at.least(1);
|
||||
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({
|
||||
"w:tc": [
|
||||
{ "w:tcPr": [] },
|
||||
{
|
||||
"w:p": [
|
||||
{ "w:pPr": [] },
|
||||
{ "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "Hello"] }] },
|
||||
],
|
||||
"w:p": [{ "w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "Hello"] }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -377,12 +359,10 @@ describe("Table", () => {
|
||||
.which.has.length.at.least(1);
|
||||
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({
|
||||
"w:tc": [
|
||||
{ "w:tcPr": [] },
|
||||
{
|
||||
"w:p": [
|
||||
{ "w:pPr": [] },
|
||||
{
|
||||
"w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "Test paragraph"] }],
|
||||
"w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "Test paragraph"] }],
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -421,22 +401,20 @@ describe("Table", () => {
|
||||
BORDERS,
|
||||
WIDTHS,
|
||||
{
|
||||
"w:tblpPr": [
|
||||
{
|
||||
_attr: {
|
||||
"w:horzAnchor": "margin",
|
||||
"w:vertAnchor": "page",
|
||||
"w:tblpX": 10,
|
||||
"w:tblpXSpec": "center",
|
||||
"w:tblpY": 20,
|
||||
"w:tblpYSpec": "bottom",
|
||||
"w:bottomFromText": 30,
|
||||
"w:topFromText": 40,
|
||||
"w:leftFromText": 50,
|
||||
"w:rightFromText": 60,
|
||||
},
|
||||
"w:tblpPr": {
|
||||
_attr: {
|
||||
"w:horzAnchor": "margin",
|
||||
"w:vertAnchor": "page",
|
||||
"w:tblpX": 10,
|
||||
"w:tblpXSpec": "center",
|
||||
"w:tblpY": 20,
|
||||
"w:tblpYSpec": "bottom",
|
||||
"w:bottomFromText": 30,
|
||||
"w:topFromText": 40,
|
||||
"w:leftFromText": 50,
|
||||
"w:rightFromText": 60,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
Reference in New Issue
Block a user