Add shading
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
export * from "./table";
|
||||
export * from "./table-cell";
|
||||
export * from "./table-properties";
|
||||
export * from "./shading";
|
||||
|
1
src/file/table/shading/index.ts
Normal file
1
src/file/table/shading/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from "./shading";
|
37
src/file/table/shading/shading.spec.ts
Normal file
37
src/file/table/shading/shading.spec.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { ShadingType, TableShading } from "./shading";
|
||||
|
||||
describe("TableShading", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should create", () => {
|
||||
const cellMargain = new TableShading({});
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({
|
||||
"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);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:shd": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "FF0000",
|
||||
"w:fill": "555555",
|
||||
"w:val": "pct40",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
64
src/file/table/shading/shading.ts
Normal file
64
src/file/table/shading/shading.ts
Normal file
@ -0,0 +1,64 @@
|
||||
// http://officeopenxml.com/WPtableShading.php
|
||||
// http://officeopenxml.com/WPtableCellProperties-Shading.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export interface ITableShadingAttributesProperties {
|
||||
readonly fill?: string;
|
||||
readonly color?: string;
|
||||
readonly val?: ShadingType;
|
||||
}
|
||||
|
||||
class TableShadingAttributes extends XmlAttributeComponent<ITableShadingAttributesProperties> {
|
||||
protected readonly xmlKeys = {
|
||||
fill: "w:fill",
|
||||
color: "w:color",
|
||||
val: "w:val",
|
||||
};
|
||||
}
|
||||
|
||||
export class TableShading extends XmlComponent {
|
||||
constructor(attrs: ITableShadingAttributesProperties) {
|
||||
super("w:shd");
|
||||
this.root.push(new TableShadingAttributes(attrs));
|
||||
}
|
||||
}
|
||||
|
||||
export enum ShadingType {
|
||||
CLEAR = "clear",
|
||||
DIAGONAL_CROSS = "diagCross",
|
||||
DIAGONAL_STRIPE = "diagStripe",
|
||||
HORIZONTAL_CROSS = "horzCross",
|
||||
HORIZONTAL_STRIPE = "horzStripe",
|
||||
NIL = "nil",
|
||||
PERCENT_5 = "pct5",
|
||||
PERCENT_10 = "pct10",
|
||||
PERCENT_12 = "pct12",
|
||||
PERCENT_15 = "pct15",
|
||||
PERCENT_20 = "pct20",
|
||||
PERCENT_25 = "pct25",
|
||||
PERCENT_30 = "pct30",
|
||||
PERCENT_35 = "pct35",
|
||||
PERCENT_37 = "pct37",
|
||||
PERCENT_40 = "pct40",
|
||||
PERCENT_45 = "pct45",
|
||||
PERCENT_50 = "pct50",
|
||||
PERCENT_55 = "pct55",
|
||||
PERCENT_60 = "pct60",
|
||||
PERCENT_62 = "pct62",
|
||||
PERCENT_65 = "pct65",
|
||||
PERCENT_70 = "pct70",
|
||||
PERCENT_75 = "pct75",
|
||||
PERCENT_80 = "pct80",
|
||||
PERCENT_85 = "pct85",
|
||||
PERCENT_87 = "pct87",
|
||||
PERCENT_90 = "pct90",
|
||||
PERCENT_95 = "pct95",
|
||||
REVERSE_DIAGONAL_STRIPE = "reverseDiagStripe",
|
||||
SOLID = "solid",
|
||||
THIN_DIAGONAL_CROSS = "thinDiagCross",
|
||||
THIN_DIAGONAL_STRIPE = "thinDiagStripe",
|
||||
THIN_HORIZONTAL_CROSS = "thinHorzCross",
|
||||
THIN_REVERSE_DIAGONAL_STRIPE = "thinReverseDiagStripe",
|
||||
THIN_VERTICAL_STRIPE = "thinVertStripe",
|
||||
VERTICAL_STRIPE = "vertStripe",
|
||||
}
|
@ -194,27 +194,3 @@ export class TableCellWidth extends XmlComponent {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export interface ITableCellShadingAttributesProperties {
|
||||
readonly fill?: string;
|
||||
readonly color?: string;
|
||||
readonly val?: string;
|
||||
}
|
||||
|
||||
class TableCellShadingAttributes extends XmlAttributeComponent<ITableCellShadingAttributesProperties> {
|
||||
protected readonly xmlKeys = {
|
||||
fill: "w:fill",
|
||||
color: "w:color",
|
||||
val: "w:val",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Table cell shading element.
|
||||
*/
|
||||
export class TableCellShading extends XmlComponent {
|
||||
constructor(attrs: ITableCellShadingAttributesProperties) {
|
||||
super("w:shd");
|
||||
this.root.push(new TableCellShadingAttributes(attrs));
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,8 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { ITableShadingAttributesProperties, TableShading } from "../shading";
|
||||
import { ITableCellMargainOptions, TableCellMargain } from "./cell-margain/table-cell-margains";
|
||||
import {
|
||||
GridSpan,
|
||||
ITableCellShadingAttributesProperties,
|
||||
TableCellBorders,
|
||||
TableCellShading,
|
||||
TableCellWidth,
|
||||
VAlign,
|
||||
VerticalAlign,
|
||||
VMerge,
|
||||
VMergeType,
|
||||
WidthType,
|
||||
} from "./table-cell-components";
|
||||
import { GridSpan, TableCellBorders, TableCellWidth, VAlign, VerticalAlign, VMerge, VMergeType, WidthType } from "./table-cell-components";
|
||||
|
||||
export class TableCellProperties extends XmlComponent {
|
||||
private readonly cellBorder: TableCellBorders;
|
||||
@ -51,8 +41,8 @@ export class TableCellProperties extends XmlComponent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public setShading(attrs: ITableCellShadingAttributesProperties): TableCellProperties {
|
||||
this.root.push(new TableCellShading(attrs));
|
||||
public setShading(attrs: ITableShadingAttributesProperties): TableCellProperties {
|
||||
this.root.push(new TableShading(attrs));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
import { Paragraph } from "file/paragraph";
|
||||
import { IXmlableObject, XmlComponent } from "file/xml-components";
|
||||
|
||||
import { ITableShadingAttributesProperties } from "../shading";
|
||||
import { Table } from "../table";
|
||||
import { ITableCellMargainOptions } from "./cell-margain/table-cell-margains";
|
||||
import { TableCellBorders, VerticalAlign, VMergeType } from "./table-cell-components";
|
||||
@ -72,6 +73,12 @@ export class TableCell extends XmlComponent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public setShading(attrs: ITableShadingAttributesProperties): TableCell {
|
||||
this.properties.setShading(attrs);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public get Borders(): TableCellBorders {
|
||||
return this.properties.Borders;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { ITableShadingAttributesProperties, TableShading } from "../shading";
|
||||
import { WidthType } from "../table-cell";
|
||||
import { TableBorders } from "./table-borders";
|
||||
import { TableCellMargin } from "./table-cell-margin";
|
||||
@ -40,4 +41,10 @@ export class TableProperties extends XmlComponent {
|
||||
this.root.push(new TableFloatProperties(tableFloatOptions));
|
||||
return this;
|
||||
}
|
||||
|
||||
public setShading(attrs: ITableShadingAttributesProperties): TableProperties {
|
||||
this.root.push(new TableShading(attrs));
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user