1 |
|
2 |
|
3 |
|
4 |
|
5 | import { downcastAttributeToStyle, upcastStyleToAttribute } from './../converters/tableproperties';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export function updateNumericAttribute(key, value, item, writer, defaultValue = 1) {
|
15 | if (value !== undefined && value !== null && defaultValue !== undefined && defaultValue !== null && value > defaultValue) {
|
16 | writer.setAttribute(key, value, item);
|
17 | }
|
18 | else {
|
19 | writer.removeAttribute(key, item);
|
20 | }
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | export function createEmptyTableCell(writer, insertPosition, attributes = {}) {
|
31 | const tableCell = writer.createElement('tableCell', attributes);
|
32 | writer.insertElement('paragraph', tableCell);
|
33 | writer.insert(tableCell, insertPosition);
|
34 | return tableCell;
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 | export function isHeadingColumnCell(tableUtils, tableCell) {
|
40 | const table = tableCell.parent.parent;
|
41 | const headingColumns = parseInt(table.getAttribute('headingColumns') || '0');
|
42 | const { column } = tableUtils.getCellLocation(tableCell);
|
43 | return !!headingColumns && column < headingColumns;
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export function enableProperty(schema, conversion, options) {
|
51 | const { modelAttribute } = options;
|
52 | schema.extend('tableCell', {
|
53 | allowAttributes: [modelAttribute]
|
54 | });
|
55 | upcastStyleToAttribute(conversion, { viewElement: /^(td|th)$/, ...options });
|
56 | downcastAttributeToStyle(conversion, { modelElement: 'tableCell', ...options });
|
57 | }
|