Introduce some functional programming techniques

This commit is contained in:
Dolan
2018-11-02 02:51:57 +00:00
parent 9cfd835171
commit 7980f14efb
108 changed files with 749 additions and 659 deletions

View File

@ -8,8 +8,8 @@ export class TableGrid extends XmlComponent {
}
}
class GridColAttributes extends XmlAttributeComponent<{ w: number }> {
protected xmlKeys = { w: "w:w" };
class GridColAttributes extends XmlAttributeComponent<{ readonly w: number }> {
protected readonly xmlKeys = { w: "w:w" };
}
export class GridCol extends XmlComponent {

View File

@ -2,13 +2,13 @@ import { BorderStyle } from "file/styles";
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components";
interface ICellBorder {
style: BorderStyle;
size: number;
color: string;
readonly style: BorderStyle;
readonly size: number;
readonly color: string;
}
class CellBorderAttributes extends XmlAttributeComponent<ICellBorder> {
protected xmlKeys = { style: "w:val", size: "w:sz", color: "w:color" };
protected readonly xmlKeys = { style: "w:val", size: "w:sz", color: "w:color" };
}
class BaseTableCellBorder extends XmlComponent {
@ -71,8 +71,8 @@ export class TableCellBorders extends XmlComponent {
/**
* Attributes fot the GridSpan element.
*/
class GridSpanAttributes extends XmlAttributeComponent<{ val: number }> {
protected xmlKeys = { val: "w:val" };
class GridSpanAttributes extends XmlAttributeComponent<{ readonly val: number }> {
protected readonly xmlKeys = { val: "w:val" };
}
/**
@ -104,8 +104,8 @@ export enum VMergeType {
RESTART = "restart",
}
class VMergeAttributes extends XmlAttributeComponent<{ val: VMergeType }> {
protected xmlKeys = { val: "w:val" };
class VMergeAttributes extends XmlAttributeComponent<{ readonly val: VMergeType }> {
protected readonly xmlKeys = { val: "w:val" };
}
/**
@ -129,8 +129,8 @@ export enum VerticalAlign {
TOP = "top",
}
class VAlignAttributes extends XmlAttributeComponent<{ val: VerticalAlign }> {
protected xmlKeys = { val: "w:val" };
class VAlignAttributes extends XmlAttributeComponent<{ readonly val: VerticalAlign }> {
protected readonly xmlKeys = { val: "w:val" };
}
/**
@ -159,8 +159,8 @@ export enum WidthType {
PERCENTAGE = "pct",
}
class TableCellWidthAttributes extends XmlAttributeComponent<{ type: WidthType; width: string | number }> {
protected xmlKeys = { width: "w:w", type: "w:type" };
class TableCellWidthAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly width: string | number }> {
protected readonly xmlKeys = { width: "w:w", type: "w:type" };
}
/**
@ -180,13 +180,13 @@ export class TableCellWidth extends XmlComponent {
}
export interface ITableCellShadingAttributesProperties {
fill?: string;
color?: string;
val?: string;
readonly fill?: string;
readonly color?: string;
readonly val?: string;
}
class TableCellShadingAttributes extends XmlAttributeComponent<ITableCellShadingAttributesProperties> {
protected xmlKeys = {
protected readonly xmlKeys = {
fill: "w:fill",
color: "w:color",
val: "w:val",

View File

@ -26,8 +26,13 @@ class TableBordersElement extends XmlComponent {
}
}
class TableBordersAttributes extends XmlAttributeComponent<{ value: string; size: number; space: number; color: string }> {
protected xmlKeys = {
class TableBordersAttributes extends XmlAttributeComponent<{
readonly value: string;
readonly size: number;
readonly space: number;
readonly color: string;
}> {
protected readonly xmlKeys = {
value: "w:val",
size: "w:sz",
space: "w:space",

View File

@ -2,8 +2,8 @@ import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-co
import { WidthType } from "../table-cell";
class TableCellMarginAttributes extends XmlAttributeComponent<{ type: WidthType; value: number }> {
protected xmlKeys = { value: "w:w", type: "w:sz" };
class TableCellMarginAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly value: number }> {
protected readonly xmlKeys = { value: "w:w", type: "w:sz" };
}
class BaseTableCellMargin extends XmlComponent {

View File

@ -32,7 +32,7 @@ export interface ITableFloatOptions {
* text - relative to the vertical edge of the text margin for the column in which the anchor paragraph is located
* If omitted, the value is assumed to be page.
*/
horizontalAnchor?: TableAnchorType;
readonly horizontalAnchor?: TableAnchorType;
/**
* Specifies an absolute horizontal position for the table, relative to the horizontalAnchor.
@ -41,7 +41,7 @@ export interface ITableFloatOptions {
* If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosition attribute is ignored.
* If the attribute is omitted, the value is assumed to be zero.
*/
absoluteHorizontalPosition?: number;
readonly absoluteHorizontalPosition?: number;
/**
* Specifies a relative horizontal position for the table, relative to the horizontalAnchor attribute.
@ -53,7 +53,7 @@ export interface ITableFloatOptions {
* outside - the table should be outside of the anchor
* right - the table should be right aligned with respect to the anchor
*/
relativeHorizontalPosition?: RelativeHorizontalPosition;
readonly relativeHorizontalPosition?: RelativeHorizontalPosition;
/**
* Specifies the vertical anchor or the base object from which the vertical positioning
@ -63,7 +63,7 @@ export interface ITableFloatOptions {
* text - relative to the horizontal edge of the text margin for the column in which the anchor paragraph is located
* If omitted, the value is assumed to be page.
*/
verticalAnchor?: TableAnchorType;
readonly verticalAnchor?: TableAnchorType;
/**
* Specifies an absolute vertical position for the table, relative to the verticalAnchor anchor.
@ -72,7 +72,7 @@ export interface ITableFloatOptions {
* If relativeVerticalPosition is also specified, then the absoluteVerticalPosition attribute is ignored.
* If the attribute is omitted, the value is assumed to be zero.
*/
absoluteVerticalPosition?: number;
readonly absoluteVerticalPosition?: number;
/**
* Specifies a relative vertical position for the table, relative to the verticalAnchor attribute.
@ -84,35 +84,35 @@ export interface ITableFloatOptions {
* inline - the table should be vertically aligned in line with the surrounding text (so as to not allow any text wrapping around it)
* top - the table should be vertically aligned to the top edge of the anchor
*/
relativeVerticalPosition?: RelativeVerticalPosition;
readonly relativeVerticalPosition?: RelativeVerticalPosition;
/**
* 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.
*/
bottomFromText?: number;
readonly bottomFromText?: number;
/**
* 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.
*/
topFromText?: number;
readonly topFromText?: number;
/**
* 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.
*/
leftFromText?: number;
readonly leftFromText?: number;
/**
* 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.
*/
rightFromText?: number;
readonly rightFromText?: number;
}
export class TableFloatOptionsAttributes extends XmlAttributeComponent<ITableFloatOptions> {
protected xmlKeys = {
protected readonly xmlKeys = {
horizontalAnchor: "w:horzAnchor",
verticalAnchor: "w:vertAnchor",
absoluteHorizontalPosition: "w:tblpX",

View File

@ -5,8 +5,8 @@ export enum TableLayoutType {
FIXED = "fixed",
}
class TableLayoutAttributes extends XmlAttributeComponent<{ type: TableLayoutType }> {
protected xmlKeys = { type: "w:type" };
class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: TableLayoutType }> {
protected readonly xmlKeys = { type: "w:type" };
}
export class TableLayout extends XmlComponent {

View File

@ -3,12 +3,12 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { WidthType } from "../table-cell";
interface ITableWidth {
type: WidthType;
w: number | string;
readonly type: WidthType;
readonly w: number | string;
}
class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> {
protected xmlKeys = { type: "w:type", w: "w:w" };
protected readonly xmlKeys = { type: "w:type", w: "w:w" };
}
export class PreferredTableWidth extends XmlComponent {