2020-01-30 16:14:25 +02:00
|
|
|
import { Paragraph } from "./paragraph";
|
2020-04-30 07:39:56 +03:00
|
|
|
import { TableCellBorders, PositionKeys } from "./table-cell-borders";
|
2020-04-27 04:41:23 +03:00
|
|
|
import { BorderPosition, TableCellBorder } from "./table-cell-border";
|
2020-01-30 16:14:25 +02:00
|
|
|
|
|
|
|
export type VMergeType = "restart" | "continue";
|
|
|
|
|
2020-03-19 18:19:39 +02:00
|
|
|
export type VAlignType = "top" | "center" | "bottom";
|
|
|
|
|
2020-01-30 16:14:25 +02:00
|
|
|
export type CellProperty = {
|
2020-04-30 07:39:56 +03:00
|
|
|
borders: TableCellBorders;
|
2020-01-30 16:14:25 +02:00
|
|
|
verticalMerge?: VMergeType;
|
2020-03-19 18:19:39 +02:00
|
|
|
verticalAlign?: VAlignType;
|
2020-01-30 16:14:25 +02:00
|
|
|
gridSpan?: number;
|
|
|
|
width?: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
export class TableCell {
|
|
|
|
children: Paragraph[] = [];
|
2020-04-30 07:39:56 +03:00
|
|
|
property: CellProperty = {
|
|
|
|
borders: new TableCellBorders(),
|
|
|
|
};
|
2020-01-30 16:14:25 +02:00
|
|
|
|
|
|
|
addParagraph(p: Paragraph) {
|
|
|
|
this.children.push(p);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
verticalMerge(t: VMergeType) {
|
|
|
|
this.property.verticalMerge = t;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:19:39 +02:00
|
|
|
verticalAlign(t: VAlignType) {
|
|
|
|
this.property.verticalAlign = t;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-01-30 16:14:25 +02:00
|
|
|
gridSpan(v: number) {
|
|
|
|
this.property.gridSpan = v;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
width(v: number) {
|
|
|
|
this.property.width = v;
|
|
|
|
return this;
|
|
|
|
}
|
2020-04-27 04:41:23 +03:00
|
|
|
|
|
|
|
setBorder(position: BorderPosition, border: TableCellBorder) {
|
2020-04-30 07:39:56 +03:00
|
|
|
this.property.borders[position.toLowerCase() as PositionKeys] = border;
|
2020-04-27 04:41:23 +03:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearBorder(position: BorderPosition) {
|
2020-04-30 07:39:56 +03:00
|
|
|
this.property.borders[
|
|
|
|
position.toLowerCase() as PositionKeys
|
2020-04-30 14:06:01 +03:00
|
|
|
] = new TableCellBorder(position).border_type("nil");
|
2020-04-27 04:41:23 +03:00
|
|
|
return this;
|
|
|
|
}
|
2020-01-30 16:14:25 +02:00
|
|
|
}
|