/
tableFormatInfo.ts
63 lines (58 loc) · 2.19 KB
/
tableFormatInfo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { getMetadata, setMetadata } from '../metadata/metadata';
import { TableBorderFormat } from 'roosterjs-editor-types';
import type { TableFormat } from 'roosterjs-editor-types';
import {
createBooleanDefinition,
createNumberDefinition,
createObjectDefinition,
createStringDefinition,
} from '../metadata/definitionCreators';
const NullStringDefinition = createStringDefinition(
false /** isOptional */,
undefined /** value */,
true /** allowNull */
);
const BooleanDefinition = createBooleanDefinition(false /** isOptional */);
const TableFormatMetadata = createObjectDefinition<Required<TableFormat>>(
{
topBorderColor: NullStringDefinition,
bottomBorderColor: NullStringDefinition,
verticalBorderColor: NullStringDefinition,
hasHeaderRow: BooleanDefinition,
headerRowColor: NullStringDefinition,
hasFirstColumn: BooleanDefinition,
hasBandedColumns: BooleanDefinition,
hasBandedRows: BooleanDefinition,
bgColorEven: NullStringDefinition,
bgColorOdd: NullStringDefinition,
tableBorderFormat: createNumberDefinition(
false /** isOptional */,
undefined /* value */,
TableBorderFormat.DEFAULT /* first table border format, TODO: Use Min/Max to specify valid values */,
TableBorderFormat.CLEAR /* last table border format, , TODO: Use Min/Max to specify valid values */
),
keepCellShade: createBooleanDefinition(true /** isOptional */),
verticalAlign: NullStringDefinition,
},
false /* isOptional */,
true /** allowNull */
);
/**
* Get the format info of a table
* If the table does not have a info saved, it will be retrieved from the css styles
* @param table The table that has the info
*/
export function getTableFormatInfo(table: HTMLTableElement) {
return getMetadata(table, TableFormatMetadata);
}
/**
* @internal
* Save the format info of a table
* @param table The table the info will be saved
* @param format The format of the table
*/
export function saveTableInfo(table: HTMLTableElement, format: TableFormat) {
if (table && format) {
setMetadata(table, format, TableFormatMetadata);
}
}