2019-11-24 03:22:50 +00:00
|
|
|
// http://officeopenxml.com/WPtableProperties.php
|
2019-04-09 05:27:18 -04:00
|
|
|
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2019-11-24 01:22:17 +00:00
|
|
|
import { Alignment, AlignmentType } from "../../paragraph";
|
2021-05-23 04:25:07 +03:00
|
|
|
import { IShadingAttributesProperties, Shading } from "../../shading";
|
2018-10-23 23:44:50 +01:00
|
|
|
import { WidthType } from "../table-cell";
|
2019-11-18 01:04:31 +00:00
|
|
|
import { ITableBordersOptions, TableBorders } from "./table-borders";
|
2021-03-04 01:42:58 +00:00
|
|
|
import { ITableCellMarginOptions, TableCellMargin } from "./table-cell-margin";
|
2018-10-23 23:44:50 +01:00
|
|
|
import { ITableFloatOptions, TableFloatProperties } from "./table-float-properties";
|
|
|
|
import { TableLayout, TableLayoutType } from "./table-layout";
|
2019-10-21 11:40:05 -05:00
|
|
|
import { TableStyle } from "./table-style";
|
2018-10-23 23:44:50 +01:00
|
|
|
import { PreferredTableWidth } from "./table-width";
|
2021-03-04 02:02:28 +00:00
|
|
|
import { VisuallyRightToLeft } from "./visually-right-to-left";
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-03-04 01:42:58 +00:00
|
|
|
export interface ITablePropertiesOptions {
|
|
|
|
readonly width?: {
|
|
|
|
readonly size: number;
|
|
|
|
readonly type?: WidthType;
|
|
|
|
};
|
|
|
|
readonly layout?: TableLayoutType;
|
|
|
|
readonly borders?: ITableBordersOptions;
|
|
|
|
readonly float?: ITableFloatOptions;
|
2021-05-23 04:25:07 +03:00
|
|
|
readonly shading?: IShadingAttributesProperties;
|
2021-03-07 21:40:42 +00:00
|
|
|
readonly style?: string;
|
2021-03-04 01:42:58 +00:00
|
|
|
readonly alignment?: AlignmentType;
|
|
|
|
readonly cellMargin?: ITableCellMarginOptions;
|
2021-03-04 02:02:28 +00:00
|
|
|
readonly visuallyRightToLeft?: boolean;
|
2021-03-04 01:42:58 +00:00
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-03-04 01:42:58 +00:00
|
|
|
export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
|
|
|
constructor(options: ITablePropertiesOptions) {
|
2018-10-23 23:44:50 +01:00
|
|
|
super("w:tblPr");
|
|
|
|
|
2021-03-22 05:54:48 +00:00
|
|
|
if (options.style) {
|
|
|
|
this.root.push(new TableStyle(options.style));
|
|
|
|
}
|
|
|
|
|
2021-05-20 01:03:09 +03:00
|
|
|
if (options.float) {
|
|
|
|
this.root.push(new TableFloatProperties(options.float));
|
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-05-20 01:03:09 +03:00
|
|
|
if (options.visuallyRightToLeft) {
|
|
|
|
this.root.push(new VisuallyRightToLeft());
|
2021-03-04 01:42:58 +00:00
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-03-04 01:42:58 +00:00
|
|
|
if (options.width) {
|
|
|
|
this.root.push(new PreferredTableWidth(options.width.type, options.width.size));
|
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
|
2021-03-04 01:42:58 +00:00
|
|
|
if (options.alignment) {
|
|
|
|
this.root.push(new Alignment(options.alignment));
|
|
|
|
}
|
2019-03-21 01:06:07 +00:00
|
|
|
|
2021-05-20 01:03:09 +03:00
|
|
|
if (options.borders) {
|
|
|
|
this.root.push(new TableBorders(options.borders));
|
|
|
|
}
|
|
|
|
|
2021-03-04 01:42:58 +00:00
|
|
|
if (options.shading) {
|
2021-05-23 04:25:07 +03:00
|
|
|
this.root.push(new Shading(options.shading));
|
2021-03-04 01:42:58 +00:00
|
|
|
}
|
2019-03-21 01:06:07 +00:00
|
|
|
|
2021-05-20 01:03:09 +03:00
|
|
|
if (options.layout) {
|
|
|
|
this.root.push(new TableLayout(options.layout));
|
2021-03-04 02:02:28 +00:00
|
|
|
}
|
2021-05-20 01:03:09 +03:00
|
|
|
|
|
|
|
this.root.push(new TableCellMargin(options.cellMargin || {}));
|
2019-10-21 11:40:05 -05:00
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
}
|