2019-04-09 05:27:18 -04:00
|
|
|
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
2018-10-23 23:44:50 +01:00
|
|
|
|
|
|
|
import { WidthType } from "../table-cell";
|
2018-08-23 00:55:33 +01:00
|
|
|
|
2018-11-02 02:51:57 +00:00
|
|
|
class TableCellMarginAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly value: number }> {
|
2019-04-08 13:50:40 -04:00
|
|
|
protected readonly xmlKeys = { value: "w:w", type: "w:type" };
|
2018-08-23 00:55:33 +01:00
|
|
|
}
|
|
|
|
|
2021-03-04 01:42:58 +00:00
|
|
|
interface IBaseTableCellMarginOptions {
|
|
|
|
readonly value: number;
|
|
|
|
readonly type?: WidthType;
|
|
|
|
}
|
|
|
|
|
2018-08-23 00:55:33 +01:00
|
|
|
class BaseTableCellMargin extends XmlComponent {
|
2021-03-04 01:42:58 +00:00
|
|
|
constructor(rootKey: string, options: IBaseTableCellMarginOptions) {
|
|
|
|
super(rootKey);
|
|
|
|
|
|
|
|
this.root.push(
|
|
|
|
new TableCellMarginAttributes({
|
|
|
|
type: options.type ?? WidthType.DXA,
|
|
|
|
value: options.value,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2018-08-23 00:55:33 +01:00
|
|
|
}
|
|
|
|
|
2021-03-04 01:42:58 +00:00
|
|
|
export interface ITableCellMarginOptions {
|
|
|
|
readonly top?: IBaseTableCellMarginOptions;
|
|
|
|
readonly bottom?: IBaseTableCellMarginOptions;
|
|
|
|
readonly left?: IBaseTableCellMarginOptions;
|
|
|
|
readonly right?: IBaseTableCellMarginOptions;
|
|
|
|
}
|
|
|
|
|
2019-04-09 05:27:18 -04:00
|
|
|
export class TableCellMargin extends IgnoreIfEmptyXmlComponent {
|
2021-03-04 01:42:58 +00:00
|
|
|
constructor(options: ITableCellMarginOptions) {
|
2018-08-23 00:55:33 +01:00
|
|
|
super("w:tblCellMar");
|
|
|
|
|
2021-03-04 01:42:58 +00:00
|
|
|
if (options.top) {
|
|
|
|
this.root.push(new BaseTableCellMargin("w:top", options.top));
|
|
|
|
}
|
2018-08-23 00:55:33 +01:00
|
|
|
|
2021-03-04 01:42:58 +00:00
|
|
|
if (options.left) {
|
|
|
|
this.root.push(new BaseTableCellMargin("w:left", options.left));
|
|
|
|
}
|
2018-08-23 00:55:33 +01:00
|
|
|
|
2021-05-20 01:03:09 +03:00
|
|
|
if (options.bottom) {
|
|
|
|
this.root.push(new BaseTableCellMargin("w:bottom", options.bottom));
|
|
|
|
}
|
|
|
|
|
2021-03-04 01:42:58 +00:00
|
|
|
if (options.right) {
|
|
|
|
this.root.push(new BaseTableCellMargin("w:right", options.right));
|
|
|
|
}
|
2018-08-23 00:55:33 +01:00
|
|
|
}
|
|
|
|
}
|