diff --git a/src/file/table/table-properties/table-float-properties.spec.ts b/src/file/table/table-properties/table-float-properties.spec.ts index ccc8cb77ef..c64e1be446 100644 --- a/src/file/table/table-properties/table-float-properties.spec.ts +++ b/src/file/table/table-properties/table-float-properties.spec.ts @@ -38,9 +38,7 @@ describe("Table Float Properties", () => { expect(tree).to.deep.equal({ "w:tblpPr": [ { - _attr: { - overlap: "never", - }, + _attr: {}, }, { "w:tblOverlap": { diff --git a/src/file/table/table-properties/table-float-properties.ts b/src/file/table/table-properties/table-float-properties.ts index e7f32dc572..1cd5e75df3 100644 --- a/src/file/table/table-properties/table-float-properties.ts +++ b/src/file/table/table-properties/table-float-properties.ts @@ -1,4 +1,4 @@ -import { StringEnumValueElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components"; +import { NextAttributeComponent, StringEnumValueElement, XmlComponent } from "@file/xml-components"; import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values"; export enum TableAnchorType { @@ -35,7 +35,7 @@ export enum OverlapType { OVERLAP = "overlap", } -export interface ITableFloatOptions { +export type ITableFloatOptions = { /* cSpell:disable */ /** * Specifies the horizontal anchor or the base object from which the horizontal positioning in the @@ -124,7 +124,7 @@ export interface ITableFloatOptions { */ readonly rightFromText?: number | PositiveUniversalMeasure; readonly overlap?: OverlapType; -} +}; // // @@ -139,51 +139,65 @@ export interface ITableFloatOptions { // // -export class TableFloatOptionsAttributes extends XmlAttributeComponent { - protected readonly xmlKeys = { - horizontalAnchor: "w:horzAnchor", - verticalAnchor: "w:vertAnchor", - absoluteHorizontalPosition: "w:tblpX", - relativeHorizontalPosition: "w:tblpXSpec", - absoluteVerticalPosition: "w:tblpY", - relativeVerticalPosition: "w:tblpYSpec", - bottomFromText: "w:bottomFromText", - topFromText: "w:topFromText", - leftFromText: "w:leftFromText", - rightFromText: "w:rightFromText", - }; -} - export class TableFloatProperties extends XmlComponent { public constructor({ + horizontalAnchor, + verticalAnchor, + absoluteHorizontalPosition, + relativeHorizontalPosition, + absoluteVerticalPosition, + relativeVerticalPosition, + bottomFromText, + topFromText, leftFromText, rightFromText, - topFromText, - bottomFromText, - absoluteHorizontalPosition, - absoluteVerticalPosition, - ...options + overlap, }: ITableFloatOptions) { super("w:tblpPr"); this.root.push( - new TableFloatOptionsAttributes({ - leftFromText: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText), - rightFromText: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText), - topFromText: topFromText === undefined ? undefined : twipsMeasureValue(topFromText), - bottomFromText: bottomFromText === undefined ? undefined : twipsMeasureValue(bottomFromText), - absoluteHorizontalPosition: - absoluteHorizontalPosition === undefined ? undefined : signedTwipsMeasureValue(absoluteHorizontalPosition), - absoluteVerticalPosition: - absoluteVerticalPosition === undefined ? undefined : signedTwipsMeasureValue(absoluteVerticalPosition), - ...options, + new NextAttributeComponent>({ + leftFromText: { key: "w:leftFromText", value: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText) }, + rightFromText: { + key: "w:rightFromText", + value: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText), + }, + topFromText: { key: "w:topFromText", value: topFromText === undefined ? undefined : twipsMeasureValue(topFromText) }, + bottomFromText: { + key: "w:bottomFromText", + value: bottomFromText === undefined ? undefined : twipsMeasureValue(bottomFromText), + }, + absoluteHorizontalPosition: { + key: "w:tblpX", + value: absoluteHorizontalPosition === undefined ? undefined : signedTwipsMeasureValue(absoluteHorizontalPosition), + }, + absoluteVerticalPosition: { + key: "w:tblpY", + value: absoluteVerticalPosition === undefined ? undefined : signedTwipsMeasureValue(absoluteVerticalPosition), + }, + horizontalAnchor: { + key: "w:horzAnchor", + value: horizontalAnchor === undefined ? undefined : horizontalAnchor, + }, + relativeHorizontalPosition: { + key: "w:tblpXSpec", + value: relativeHorizontalPosition, + }, + relativeVerticalPosition: { + key: "w:tblpYSpec", + value: relativeVerticalPosition, + }, + verticalAnchor: { + key: "w:vertAnchor", + value: verticalAnchor, + }, }), ); - if (options.overlap) { + if (overlap) { // // // - this.root.push(new StringEnumValueElement("w:tblOverlap", options.overlap)); + this.root.push(new StringEnumValueElement("w:tblOverlap", overlap)); } } } diff --git a/src/file/xml-components/simple-elements.spec.ts b/src/file/xml-components/simple-elements.spec.ts new file mode 100644 index 0000000000..049389a353 --- /dev/null +++ b/src/file/xml-components/simple-elements.spec.ts @@ -0,0 +1,41 @@ +import { expect } from "chai"; + +import { Formatter } from "@export/formatter"; + +import { BuilderElement } from "./simple-elements"; + +describe("BuilderElement", () => { + describe("#constructor()", () => { + it("should create a simple BuilderElement", () => { + const element = new BuilderElement({ + name: "test", + }); + + const tree = new Formatter().format(element); + expect(tree).to.deep.equal({ + test: {}, + }); + }); + + it("should create a simple BuilderElement with attributes", () => { + const element = new BuilderElement<{ readonly testAttr: string }>({ + name: "test", + attributes: { + testAttr: { + key: "w:testAttr", + value: "test", + }, + }, + }); + + const tree = new Formatter().format(element); + expect(tree).to.deep.equal({ + test: { + _attr: { + "w:testAttr": "test", + }, + }, + }); + }); + }); +}); diff --git a/src/file/xml-components/simple-elements.ts b/src/file/xml-components/simple-elements.ts index 6ed117b7ba..dab6f618bc 100644 --- a/src/file/xml-components/simple-elements.ts +++ b/src/file/xml-components/simple-elements.ts @@ -92,5 +92,7 @@ export class BuilderElement extends XmlComponent { if (options.attributes) { this.root.push(new NextAttributeComponent(options.attributes)); } + + // TODO: Children } }