add values checks to remaining file/table code
This commit is contained in:
@ -20,7 +20,7 @@
|
|||||||
// <xsd:attribute name="frame" type="s:ST_OnOff" use="optional"/>
|
// <xsd:attribute name="frame" type="s:ST_OnOff" use="optional"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
import { hexColorValue } from "../values";
|
import { eighthPointMeasureValue, hexColorValue, pointMeasureValue } from "../values";
|
||||||
|
|
||||||
export interface IBorderOptions {
|
export interface IBorderOptions {
|
||||||
readonly style: BorderStyle;
|
readonly style: BorderStyle;
|
||||||
@ -30,12 +30,14 @@ export interface IBorderOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class BorderElement extends XmlComponent {
|
export class BorderElement extends XmlComponent {
|
||||||
constructor(elementName: string, { color, ...options }: IBorderOptions) {
|
constructor(elementName: string, { color, size, space, style }: IBorderOptions) {
|
||||||
super(elementName);
|
super(elementName);
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new BordersAttributes({
|
new BordersAttributes({
|
||||||
...options,
|
style,
|
||||||
color: color === undefined ? color : hexColorValue(color),
|
color: color === undefined ? undefined : hexColorValue(color),
|
||||||
|
size: size === undefined ? undefined : eighthPointMeasureValue(size),
|
||||||
|
space: space === undefined ? undefined : pointMeasureValue(space),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ export class Shading extends XmlComponent {
|
|||||||
super("w:shd");
|
super("w:shd");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new ShadingAttributes({
|
new ShadingAttributes({
|
||||||
fill: fill === undefined ? fill : hexColorValue(fill),
|
fill: fill === undefined ? undefined : hexColorValue(fill),
|
||||||
color: color === undefined ? color : hexColorValue(color),
|
color: color === undefined ? undefined : hexColorValue(color),
|
||||||
val,
|
val,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,22 @@
|
|||||||
import { BorderElement, IBorderOptions } from "file/border";
|
import { BorderElement, IBorderOptions } from "file/border";
|
||||||
|
import { decimalNumber } from "file/values";
|
||||||
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
// <xsd:complexType name="CT_TcBorders">
|
||||||
|
// <xsd:sequence>
|
||||||
|
// <xsd:element name="top" type="CT_Border" minOccurs="0"/>
|
||||||
|
// <xsd:element name="start" type="CT_Border" minOccurs="0"/>
|
||||||
|
// <xsd:element name="left" type="CT_Border" minOccurs="0"/>
|
||||||
|
// <xsd:element name="bottom" type="CT_Border" minOccurs="0"/>
|
||||||
|
// <xsd:element name="end" type="CT_Border" minOccurs="0"/>
|
||||||
|
// <xsd:element name="right" type="CT_Border" minOccurs="0"/>
|
||||||
|
// <xsd:element name="insideH" type="CT_Border" minOccurs="0"/>
|
||||||
|
// <xsd:element name="insideV" type="CT_Border" minOccurs="0"/>
|
||||||
|
// <xsd:element name="tl2br" type="CT_Border" minOccurs="0"/>
|
||||||
|
// <xsd:element name="tr2bl" type="CT_Border" minOccurs="0"/>
|
||||||
|
// </xsd:sequence>
|
||||||
|
// </xsd:complexType>
|
||||||
|
|
||||||
export interface ITableCellBorders {
|
export interface ITableCellBorders {
|
||||||
readonly top?: IBorderOptions;
|
readonly top?: IBorderOptions;
|
||||||
readonly start?: IBorderOptions;
|
readonly start?: IBorderOptions;
|
||||||
@ -42,6 +58,10 @@ class GridSpanAttributes extends XmlAttributeComponent<{ readonly val: number }>
|
|||||||
protected readonly xmlKeys = { val: "w:val" };
|
protected readonly xmlKeys = { val: "w:val" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <xsd:complexType name="CT_TcPrBase">
|
||||||
|
// ...
|
||||||
|
// <xsd:element name="gridSpan" type="CT_DecimalNumber" minOccurs="0"/>
|
||||||
|
// </xsd>
|
||||||
/**
|
/**
|
||||||
* GridSpan element. Should be used in a table cell. Pass the number of columns that this cell need to span.
|
* GridSpan element. Should be used in a table cell. Pass the number of columns that this cell need to span.
|
||||||
*/
|
*/
|
||||||
@ -51,7 +71,7 @@ export class GridSpan extends XmlComponent {
|
|||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new GridSpanAttributes({
|
new GridSpanAttributes({
|
||||||
val: value,
|
val: decimalNumber(value),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { signedTwipsMeasureValue, twipsMeasureValue } from "file/values";
|
||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
import { OverlapType, TableOverlap } from "./table-overlap";
|
import { OverlapType, TableOverlap } from "./table-overlap";
|
||||||
@ -43,7 +44,7 @@ export interface ITableFloatOptions {
|
|||||||
* If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosition attribute is ignored.
|
* If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosition attribute is ignored.
|
||||||
* If the attribute is omitted, the value is assumed to be zero.
|
* If the attribute is omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly absoluteHorizontalPosition?: number;
|
readonly absoluteHorizontalPosition?: number | string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies a relative horizontal position for the table, relative to the horizontalAnchor attribute.
|
* Specifies a relative horizontal position for the table, relative to the horizontalAnchor attribute.
|
||||||
@ -74,7 +75,7 @@ export interface ITableFloatOptions {
|
|||||||
* If relativeVerticalPosition is also specified, then the absoluteVerticalPosition attribute is ignored.
|
* If relativeVerticalPosition is also specified, then the absoluteVerticalPosition attribute is ignored.
|
||||||
* If the attribute is omitted, the value is assumed to be zero.
|
* If the attribute is omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly absoluteVerticalPosition?: number;
|
readonly absoluteVerticalPosition?: number | string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies a relative vertical position for the table, relative to the verticalAnchor attribute.
|
* Specifies a relative vertical position for the table, relative to the verticalAnchor attribute.
|
||||||
@ -92,28 +93,41 @@ export interface ITableFloatOptions {
|
|||||||
* Specifies the minimun distance to be maintained between the table and the top of text in the paragraph
|
* Specifies the minimun distance to be maintained between the table and the top of text in the paragraph
|
||||||
* below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
* below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly bottomFromText?: number;
|
readonly bottomFromText?: number | string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the minimun distance to be maintained between the table and the bottom edge of text in the paragraph
|
* Specifies the minimun distance to be maintained between the table and the bottom edge of text in the paragraph
|
||||||
* above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
* above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly topFromText?: number;
|
readonly topFromText?: number | string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph
|
* Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph
|
||||||
* to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
* to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly leftFromText?: number;
|
readonly leftFromText?: number | string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph
|
* Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph
|
||||||
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly rightFromText?: number;
|
readonly rightFromText?: number | string;
|
||||||
readonly overlap?: OverlapType;
|
readonly overlap?: OverlapType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <xsd:complexType name="CT_TblPPr">
|
||||||
|
// <xsd:attribute name="leftFromText" type="s:ST_TwipsMeasure"/>
|
||||||
|
// <xsd:attribute name="rightFromText" type="s:ST_TwipsMeasure"/>
|
||||||
|
// <xsd:attribute name="topFromText" type="s:ST_TwipsMeasure"/>
|
||||||
|
// <xsd:attribute name="bottomFromText" type="s:ST_TwipsMeasure"/>
|
||||||
|
// <xsd:attribute name="vertAnchor" type="ST_VAnchor"/>
|
||||||
|
// <xsd:attribute name="horzAnchor" type="ST_HAnchor"/>
|
||||||
|
// <xsd:attribute name="tblpXSpec" type="s:ST_XAlign"/>
|
||||||
|
// <xsd:attribute name="tblpX" type="ST_SignedTwipsMeasure"/>
|
||||||
|
// <xsd:attribute name="tblpYSpec" type="s:ST_YAlign"/>
|
||||||
|
// <xsd:attribute name="tblpY" type="ST_SignedTwipsMeasure"/>
|
||||||
|
// </xsd:complexType>
|
||||||
|
|
||||||
export class TableFloatOptionsAttributes extends XmlAttributeComponent<ITableFloatOptions> {
|
export class TableFloatOptionsAttributes extends XmlAttributeComponent<ITableFloatOptions> {
|
||||||
protected readonly xmlKeys = {
|
protected readonly xmlKeys = {
|
||||||
horizontalAnchor: "w:horzAnchor",
|
horizontalAnchor: "w:horzAnchor",
|
||||||
@ -129,23 +143,30 @@ export class TableFloatOptionsAttributes extends XmlAttributeComponent<ITableFlo
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xsd:complexType name="CT_TblPPr">
|
|
||||||
// <xsd:attribute name="leftFromText" type="s:ST_TwipsMeasure"/>
|
|
||||||
// <xsd:attribute name="rightFromText" type="s:ST_TwipsMeasure"/>
|
|
||||||
// <xsd:attribute name="topFromText" type="s:ST_TwipsMeasure"/>
|
|
||||||
// <xsd:attribute name="bottomFromText" type="s:ST_TwipsMeasure"/>
|
|
||||||
// <xsd:attribute name="vertAnchor" type="ST_VAnchor"/>
|
|
||||||
// <xsd:attribute name="horzAnchor" type="ST_HAnchor"/>
|
|
||||||
// <xsd:attribute name="tblpXSpec" type="s:ST_XAlign"/>
|
|
||||||
// <xsd:attribute name="tblpX" type="ST_SignedTwipsMeasure"/>
|
|
||||||
// <xsd:attribute name="tblpYSpec" type="s:ST_YAlign"/>
|
|
||||||
// <xsd:attribute name="tblpY" type="ST_SignedTwipsMeasure"/>
|
|
||||||
// </xsd:complexType>
|
|
||||||
|
|
||||||
export class TableFloatProperties extends XmlComponent {
|
export class TableFloatProperties extends XmlComponent {
|
||||||
constructor(options: ITableFloatOptions) {
|
constructor({
|
||||||
|
leftFromText,
|
||||||
|
rightFromText,
|
||||||
|
topFromText,
|
||||||
|
bottomFromText,
|
||||||
|
absoluteHorizontalPosition,
|
||||||
|
absoluteVerticalPosition,
|
||||||
|
...options
|
||||||
|
}: ITableFloatOptions) {
|
||||||
super("w:tblpPr");
|
super("w:tblpPr");
|
||||||
this.root.push(new TableFloatOptionsAttributes(options));
|
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,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
if (options.overlap) {
|
if (options.overlap) {
|
||||||
this.root.push(new TableOverlap(options.overlap));
|
this.root.push(new TableOverlap(options.overlap));
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_TblLayoutType">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="fixed"/>
|
||||||
|
// <xsd:enumeration value="autofit"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
export enum TableLayoutType {
|
export enum TableLayoutType {
|
||||||
AUTOFIT = "autofit",
|
AUTOFIT = "autofit",
|
||||||
FIXED = "fixed",
|
FIXED = "fixed",
|
||||||
@ -12,12 +18,6 @@ class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: Table
|
|||||||
// <xsd:complexType name="CT_TblLayoutType">
|
// <xsd:complexType name="CT_TblLayoutType">
|
||||||
// <xsd:attribute name="type" type="ST_TblLayoutType"/>
|
// <xsd:attribute name="type" type="ST_TblLayoutType"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
// <xsd:simpleType name="ST_TblLayoutType">
|
|
||||||
// <xsd:restriction base="xsd:string">
|
|
||||||
// <xsd:enumeration value="fixed"/>
|
|
||||||
// <xsd:enumeration value="autofit"/>
|
|
||||||
// </xsd:restriction>
|
|
||||||
// </xsd:simpleType>
|
|
||||||
export class TableLayout extends XmlComponent {
|
export class TableLayout extends XmlComponent {
|
||||||
constructor(type: TableLayoutType) {
|
constructor(type: TableLayoutType) {
|
||||||
super("w:tblLayout");
|
super("w:tblLayout");
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_TblOverlap">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="never"/>
|
||||||
|
// <xsd:enumeration value="overlap"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
export enum OverlapType {
|
export enum OverlapType {
|
||||||
NEVER = "never",
|
NEVER = "never",
|
||||||
OVERLAP = "overlap",
|
OVERLAP = "overlap",
|
||||||
@ -8,13 +14,6 @@ export enum OverlapType {
|
|||||||
// <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>
|
||||||
// <xsd:simpleType name="ST_TblOverlap">
|
|
||||||
// <xsd:restriction base="xsd:string">
|
|
||||||
// <xsd:enumeration value="never"/>
|
|
||||||
// <xsd:enumeration value="overlap"/>
|
|
||||||
// </xsd:restriction>
|
|
||||||
// </xsd:simpleType>
|
|
||||||
|
|
||||||
class TableOverlapAttributes extends XmlAttributeComponent<{ readonly val: OverlapType }> {
|
class TableOverlapAttributes extends XmlAttributeComponent<{ readonly val: OverlapType }> {
|
||||||
protected readonly xmlKeys = { val: "w:val" };
|
protected readonly xmlKeys = { val: "w:val" };
|
||||||
}
|
}
|
||||||
|
@ -136,3 +136,13 @@ export function percentageValue(val: string): string {
|
|||||||
export function measurementOrPercentValue(val: number | string): number | string {
|
export function measurementOrPercentValue(val: number | string): number | string {
|
||||||
return typeof val === "number" ? decimalNumber(val) : percentageValue(val);
|
return typeof val === "number" ? decimalNumber(val) : percentageValue(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_EighthPointMeasure">
|
||||||
|
// <xsd:restriction base="s:ST_UnsignedDecimalNumber"/>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
export const eighthPointMeasureValue = unsignedDecimalNumber;
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_PointMeasure">
|
||||||
|
// <xsd:restriction base="s:ST_UnsignedDecimalNumber"/>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
export const pointMeasureValue = unsignedDecimalNumber;
|
||||||
|
Reference in New Issue
Block a user