Merge pull request #1920 from dolanmiu/feat/float-options
Use next attribute component
This commit is contained in:
@ -38,9 +38,7 @@ describe("Table Float Properties", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tblpPr": [
|
"w:tblpPr": [
|
||||||
{
|
{
|
||||||
_attr: {
|
_attr: {},
|
||||||
overlap: "never",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:tblOverlap": {
|
"w:tblOverlap": {
|
||||||
|
@ -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";
|
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
export enum TableAnchorType {
|
export enum TableAnchorType {
|
||||||
@ -35,7 +35,7 @@ export enum OverlapType {
|
|||||||
OVERLAP = "overlap",
|
OVERLAP = "overlap",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITableFloatOptions {
|
export type ITableFloatOptions = {
|
||||||
/* cSpell:disable */
|
/* cSpell:disable */
|
||||||
/**
|
/**
|
||||||
* Specifies the horizontal anchor or the base object from which the horizontal positioning in the
|
* 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 rightFromText?: number | PositiveUniversalMeasure;
|
||||||
readonly overlap?: OverlapType;
|
readonly overlap?: OverlapType;
|
||||||
}
|
};
|
||||||
|
|
||||||
// <xsd:complexType name="CT_TblPPr">
|
// <xsd:complexType name="CT_TblPPr">
|
||||||
// <xsd:attribute name="leftFromText" type="s:ST_TwipsMeasure"/>
|
// <xsd:attribute name="leftFromText" type="s:ST_TwipsMeasure"/>
|
||||||
@ -139,51 +139,65 @@ export interface ITableFloatOptions {
|
|||||||
// <xsd:attribute name="tblpY" type="ST_SignedTwipsMeasure"/>
|
// <xsd:attribute name="tblpY" type="ST_SignedTwipsMeasure"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
|
|
||||||
export class TableFloatOptionsAttributes extends XmlAttributeComponent<ITableFloatOptions> {
|
|
||||||
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 {
|
export class TableFloatProperties extends XmlComponent {
|
||||||
public constructor({
|
public constructor({
|
||||||
|
horizontalAnchor,
|
||||||
|
verticalAnchor,
|
||||||
|
absoluteHorizontalPosition,
|
||||||
|
relativeHorizontalPosition,
|
||||||
|
absoluteVerticalPosition,
|
||||||
|
relativeVerticalPosition,
|
||||||
|
bottomFromText,
|
||||||
|
topFromText,
|
||||||
leftFromText,
|
leftFromText,
|
||||||
rightFromText,
|
rightFromText,
|
||||||
topFromText,
|
overlap,
|
||||||
bottomFromText,
|
|
||||||
absoluteHorizontalPosition,
|
|
||||||
absoluteVerticalPosition,
|
|
||||||
...options
|
|
||||||
}: ITableFloatOptions) {
|
}: ITableFloatOptions) {
|
||||||
super("w:tblpPr");
|
super("w:tblpPr");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new TableFloatOptionsAttributes({
|
new NextAttributeComponent<Omit<ITableFloatOptions, "overlap">>({
|
||||||
leftFromText: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText),
|
leftFromText: { key: "w:leftFromText", value: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText) },
|
||||||
rightFromText: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText),
|
rightFromText: {
|
||||||
topFromText: topFromText === undefined ? undefined : twipsMeasureValue(topFromText),
|
key: "w:rightFromText",
|
||||||
bottomFromText: bottomFromText === undefined ? undefined : twipsMeasureValue(bottomFromText),
|
value: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText),
|
||||||
absoluteHorizontalPosition:
|
},
|
||||||
absoluteHorizontalPosition === undefined ? undefined : signedTwipsMeasureValue(absoluteHorizontalPosition),
|
topFromText: { key: "w:topFromText", value: topFromText === undefined ? undefined : twipsMeasureValue(topFromText) },
|
||||||
absoluteVerticalPosition:
|
bottomFromText: {
|
||||||
absoluteVerticalPosition === undefined ? undefined : signedTwipsMeasureValue(absoluteVerticalPosition),
|
key: "w:bottomFromText",
|
||||||
...options,
|
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) {
|
||||||
// <xsd:complexType name="CT_TblOverlap">
|
// <xsd:complexType name="CT_TblOverlap">
|
||||||
// <xsd:attribute name="val" type="ST_TblOverlap" use="required"/>
|
// <xsd:attribute name="val" type="ST_TblOverlap" use="required"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
this.root.push(new StringEnumValueElement<OverlapType>("w:tblOverlap", options.overlap));
|
this.root.push(new StringEnumValueElement<OverlapType>("w:tblOverlap", overlap));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
src/file/xml-components/simple-elements.spec.ts
Normal file
41
src/file/xml-components/simple-elements.spec.ts
Normal file
@ -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",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -92,5 +92,7 @@ export class BuilderElement<T extends AttributeData> extends XmlComponent {
|
|||||||
if (options.attributes) {
|
if (options.attributes) {
|
||||||
this.root.push(new NextAttributeComponent(options.attributes));
|
this.root.push(new NextAttributeComponent(options.attributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Children
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user