2025-05-02 13:58:10 -05:00
|
|
|
import { TableVerticalAlign, VerticalAlignElement } from "@file/vertical-align";
|
2022-06-26 23:26:42 +01: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";
|
2021-05-23 21:17:20 +03:00
|
|
|
import { ITableCellMarginOptions, TableCellMargin, TableCellMarginElementType } from "../table-properties/table-cell-margin";
|
|
|
|
import { ITableWidthProperties, TableWidthElement } from "../table-width";
|
2019-09-26 02:03:17 +01:00
|
|
|
import {
|
|
|
|
GridSpan,
|
2021-05-22 04:03:40 +03:00
|
|
|
ITableCellBorders,
|
2020-05-10 10:36:25 -07:00
|
|
|
TDirection,
|
2024-10-21 03:57:15 +01:00
|
|
|
TableCellBorders,
|
2020-05-10 10:36:25 -07:00
|
|
|
TextDirection,
|
2019-09-26 02:03:17 +01:00
|
|
|
VerticalMerge,
|
|
|
|
VerticalMergeType,
|
|
|
|
} from "./table-cell-components";
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2024-10-21 03:57:15 +01:00
|
|
|
export type ITableCellPropertiesOptions = {
|
2021-05-23 04:25:07 +03:00
|
|
|
readonly shading?: IShadingAttributesProperties;
|
2021-05-22 04:03:40 +03:00
|
|
|
readonly margins?: ITableCellMarginOptions;
|
2025-05-02 13:58:10 -05:00
|
|
|
readonly verticalAlign?: TableVerticalAlign;
|
2023-12-22 10:25:00 +09:00
|
|
|
readonly textDirection?: (typeof TextDirection)[keyof typeof TextDirection];
|
|
|
|
readonly verticalMerge?: (typeof VerticalMergeType)[keyof typeof VerticalMergeType];
|
2021-05-23 21:17:20 +03:00
|
|
|
readonly width?: ITableWidthProperties;
|
2021-05-22 04:03:40 +03:00
|
|
|
readonly columnSpan?: number;
|
|
|
|
readonly rowSpan?: number;
|
|
|
|
readonly borders?: ITableCellBorders;
|
2024-10-21 03:57:15 +01:00
|
|
|
};
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public 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) {
|
2021-05-23 21:17:20 +03:00
|
|
|
this.root.push(new TableWidthElement("w:tcW", options.width));
|
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.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) {
|
2021-05-23 21:17:20 +03:00
|
|
|
this.root.push(new TableCellMargin(TableCellMarginElementType.TABLE_CELL, options.margins));
|
2021-05-22 04:03:40 +03:00
|
|
|
}
|
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) {
|
2021-05-24 21:06:34 +03:00
|
|
|
this.root.push(new VerticalAlignElement(options.verticalAlign));
|
2021-05-22 04:03:40 +03:00
|
|
|
}
|
2021-05-20 01:03:09 +03:00
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
}
|