2019-04-09 05:27:18 -04:00
|
|
|
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-05-23 04:25:07 +03:00
|
|
|
import { IShadingAttributesProperties, Shading } from "../../shading";
|
2019-04-18 13:55:18 +10:00
|
|
|
import { ITableCellMarginOptions, TableCellMargin } from "./cell-margin/table-cell-margins";
|
2019-09-26 02:03:17 +01:00
|
|
|
import {
|
|
|
|
GridSpan,
|
2021-05-22 04:03:40 +03:00
|
|
|
ITableCellBorders,
|
2019-09-26 02:03:17 +01:00
|
|
|
TableCellBorders,
|
|
|
|
TableCellWidth,
|
2020-05-10 10:36:25 -07:00
|
|
|
TDirection,
|
|
|
|
TextDirection,
|
2019-09-26 02:03:17 +01:00
|
|
|
VAlign,
|
|
|
|
VerticalAlign,
|
|
|
|
VerticalMerge,
|
|
|
|
VerticalMergeType,
|
|
|
|
WidthType,
|
|
|
|
} from "./table-cell-components";
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
export interface ITableCellPropertiesOptions {
|
2021-05-23 04:25:07 +03:00
|
|
|
readonly shading?: IShadingAttributesProperties;
|
2021-05-22 04:03:40 +03:00
|
|
|
readonly margins?: ITableCellMarginOptions;
|
|
|
|
readonly verticalAlign?: VerticalAlign;
|
|
|
|
readonly textDirection?: TextDirection;
|
|
|
|
readonly verticalMerge?: VerticalMergeType;
|
|
|
|
readonly width?: {
|
|
|
|
readonly size: number | string;
|
|
|
|
readonly type?: WidthType;
|
|
|
|
};
|
|
|
|
readonly columnSpan?: number;
|
|
|
|
readonly rowSpan?: number;
|
|
|
|
readonly borders?: ITableCellBorders;
|
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
|
|
|
|
constructor(options: ITableCellPropertiesOptions) {
|
2018-10-23 23:44:50 +01:00
|
|
|
super("w:tcPr");
|
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
if (options.width) {
|
|
|
|
this.root.push(new TableCellWidth(options.width.size, options.width.type));
|
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
if (options.columnSpan) {
|
|
|
|
this.root.push(new GridSpan(options.columnSpan));
|
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
if (options.verticalMerge) {
|
|
|
|
this.root.push(new VerticalMerge(options.verticalMerge));
|
|
|
|
} else if (options.rowSpan && options.rowSpan > 1) {
|
|
|
|
// if cell already have a `verticalMerge`, don't handle `rowSpan`
|
|
|
|
this.root.push(new VerticalMerge(VerticalMergeType.RESTART));
|
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
if (options.borders) {
|
|
|
|
this.root.push(new TableCellBorders(options.borders));
|
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
if (options.shading) {
|
2021-05-23 04:25:07 +03:00
|
|
|
this.root.push(new Shading(options.shading));
|
2021-05-22 04:03:40 +03:00
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
if (options.margins) {
|
|
|
|
this.root.push(new TableCellMargin(options.margins));
|
|
|
|
}
|
2021-05-20 01:03:09 +03:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
if (options.textDirection) {
|
|
|
|
this.root.push(new TDirection(options.textDirection));
|
|
|
|
}
|
2021-05-20 01:03:09 +03:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
if (options.verticalAlign) {
|
|
|
|
this.root.push(new VAlign(options.verticalAlign));
|
|
|
|
}
|
2021-05-20 01:03:09 +03:00
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
}
|