Files
docx-js/src/file/table/table-cell/table-cell-properties.ts

74 lines
2.2 KiB
TypeScript
Raw Normal View History

import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
2018-10-23 23:44:50 +01: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,
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
export interface ITableCellPropertiesOptions {
readonly shading?: IShadingAttributesProperties;
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
export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
constructor(options: ITableCellPropertiesOptions) {
2018-10-23 23:44:50 +01:00
super("w:tcPr");
if (options.width) {
this.root.push(new TableCellWidth(options.width.size, options.width.type));
}
2018-10-23 23:44:50 +01:00
if (options.columnSpan) {
this.root.push(new GridSpan(options.columnSpan));
}
2018-10-23 23:44:50 +01: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
if (options.borders) {
this.root.push(new TableCellBorders(options.borders));
}
2018-10-23 23:44:50 +01:00
if (options.shading) {
this.root.push(new Shading(options.shading));
}
2018-10-23 23:44:50 +01:00
if (options.margins) {
this.root.push(new TableCellMargin(options.margins));
}
if (options.textDirection) {
this.root.push(new TDirection(options.textDirection));
}
if (options.verticalAlign) {
this.root.push(new VAlign(options.verticalAlign));
}
}
2018-10-23 23:44:50 +01:00
}