@ckeditor/ckeditor5-table 36.0.0 → 37.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/table.js +1 -1
- package/package.json +34 -29
- package/src/commands/insertcolumncommand.d.ts +61 -0
- package/src/commands/insertcolumncommand.js +45 -60
- package/src/commands/insertrowcommand.d.ts +60 -0
- package/src/commands/insertrowcommand.js +44 -59
- package/src/commands/inserttablecommand.d.ts +50 -0
- package/src/commands/inserttablecommand.js +51 -68
- package/src/commands/mergecellcommand.d.ts +76 -0
- package/src/commands/mergecellcommand.js +169 -244
- package/src/commands/mergecellscommand.d.ts +33 -0
- package/src/commands/mergecellscommand.js +72 -101
- package/src/commands/removecolumncommand.d.ts +34 -0
- package/src/commands/removecolumncommand.js +88 -102
- package/src/commands/removerowcommand.d.ts +34 -0
- package/src/commands/removerowcommand.js +63 -80
- package/src/commands/selectcolumncommand.d.ts +38 -0
- package/src/commands/selectcolumncommand.js +41 -54
- package/src/commands/selectrowcommand.d.ts +38 -0
- package/src/commands/selectrowcommand.js +38 -48
- package/src/commands/setheadercolumncommand.d.ts +55 -0
- package/src/commands/setheadercolumncommand.js +48 -73
- package/src/commands/setheaderrowcommand.d.ts +58 -0
- package/src/commands/setheaderrowcommand.js +56 -85
- package/src/commands/splitcellcommand.d.ts +49 -0
- package/src/commands/splitcellcommand.js +35 -49
- package/src/converters/downcast.d.ts +63 -0
- package/src/converters/downcast.js +98 -130
- package/src/converters/table-caption-post-fixer.d.ts +20 -0
- package/src/converters/table-caption-post-fixer.js +36 -52
- package/src/converters/table-cell-paragraph-post-fixer.d.ts +32 -0
- package/src/converters/table-cell-paragraph-post-fixer.js +88 -119
- package/src/converters/table-cell-refresh-handler.d.ts +18 -0
- package/src/converters/table-cell-refresh-handler.js +29 -48
- package/src/converters/table-headings-refresh-handler.d.ts +17 -0
- package/src/converters/table-headings-refresh-handler.js +35 -54
- package/src/converters/table-layout-post-fixer.d.ts +226 -0
- package/src/converters/table-layout-post-fixer.js +276 -313
- package/src/converters/tableproperties.d.ts +54 -0
- package/src/converters/tableproperties.js +136 -168
- package/src/converters/upcasttable.d.ts +49 -0
- package/src/converters/upcasttable.js +196 -251
- package/src/index.d.ts +29 -0
- package/src/index.js +0 -2
- package/src/plaintableoutput.d.ts +30 -0
- package/src/plaintableoutput.js +107 -135
- package/src/table.d.ts +38 -0
- package/src/table.js +12 -88
- package/src/tablecaption/tablecaptionediting.d.ts +68 -0
- package/src/tablecaption/tablecaptionediting.js +104 -135
- package/src/tablecaption/tablecaptionui.d.ts +26 -0
- package/src/tablecaption/tablecaptionui.js +42 -58
- package/src/tablecaption/toggletablecaptioncommand.d.ts +73 -0
- package/src/tablecaption/toggletablecaptioncommand.js +77 -92
- package/src/tablecaption/utils.d.ts +42 -0
- package/src/tablecaption/utils.js +35 -61
- package/src/tablecaption.d.ts +27 -0
- package/src/tablecaption.js +12 -19
- package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.d.ts +37 -0
- package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +14 -20
- package/src/tablecellproperties/commands/tablecellbordercolorcommand.d.ts +42 -0
- package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +27 -37
- package/src/tablecellproperties/commands/tablecellborderstylecommand.d.ts +42 -0
- package/src/tablecellproperties/commands/tablecellborderstylecommand.js +27 -37
- package/src/tablecellproperties/commands/tablecellborderwidthcommand.d.ts +56 -0
- package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +42 -53
- package/src/tablecellproperties/commands/tablecellheightcommand.d.ts +51 -0
- package/src/tablecellproperties/commands/tablecellheightcommand.js +29 -36
- package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.d.ts +37 -0
- package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +14 -20
- package/src/tablecellproperties/commands/tablecellpaddingcommand.d.ts +56 -0
- package/src/tablecellproperties/commands/tablecellpaddingcommand.js +42 -53
- package/src/tablecellproperties/commands/tablecellpropertycommand.d.ts +62 -0
- package/src/tablecellproperties/commands/tablecellpropertycommand.js +77 -122
- package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.d.ts +45 -0
- package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +14 -20
- package/src/tablecellproperties/tablecellpropertiesediting.d.ts +47 -0
- package/src/tablecellproperties/tablecellpropertiesediting.js +194 -236
- package/src/tablecellproperties/tablecellpropertiesui.d.ts +117 -0
- package/src/tablecellproperties/tablecellpropertiesui.js +303 -456
- package/src/tablecellproperties/ui/tablecellpropertiesview.d.ts +227 -0
- package/src/tablecellproperties/ui/tablecellpropertiesview.js +509 -844
- package/src/tablecellproperties.d.ts +33 -0
- package/src/tablecellproperties.js +12 -98
- package/src/tablecellwidth/commands/tablecellwidthcommand.d.ts +51 -0
- package/src/tablecellwidth/commands/tablecellwidthcommand.js +29 -35
- package/src/tablecellwidth/tablecellwidthediting.d.ts +34 -0
- package/src/tablecellwidth/tablecellwidthediting.js +26 -38
- package/src/tableclipboard.d.ts +68 -0
- package/src/tableclipboard.js +429 -568
- package/src/tablecolumnresize/constants.d.ts +20 -0
- package/src/tablecolumnresize/constants.js +0 -10
- package/src/tablecolumnresize/converters.d.ts +18 -0
- package/src/tablecolumnresize/converters.js +35 -119
- package/src/tablecolumnresize/tablecolumnresizeediting.d.ts +142 -0
- package/src/tablecolumnresize/tablecolumnresizeediting.js +545 -711
- package/src/tablecolumnresize/tablewidthscommand.d.ts +38 -0
- package/src/tablecolumnresize/tablewidthscommand.js +61 -0
- package/src/tablecolumnresize/utils.d.ts +141 -0
- package/src/tablecolumnresize/utils.js +256 -233
- package/src/tablecolumnresize.d.ts +29 -0
- package/src/tablecolumnresize.js +12 -19
- package/src/tableconfig.d.ts +341 -0
- package/src/tableconfig.js +5 -0
- package/src/tableediting.d.ts +102 -0
- package/src/tableediting.js +157 -176
- package/src/tablekeyboard.d.ts +68 -0
- package/src/tablekeyboard.js +261 -344
- package/src/tablemouse/mouseeventsobserver.d.ts +62 -0
- package/src/tablemouse/mouseeventsobserver.js +12 -49
- package/src/tablemouse.d.ts +51 -0
- package/src/tablemouse.js +154 -202
- package/src/tableproperties/commands/tablealignmentcommand.d.ts +37 -0
- package/src/tableproperties/commands/tablealignmentcommand.js +14 -20
- package/src/tableproperties/commands/tablebackgroundcolorcommand.d.ts +37 -0
- package/src/tableproperties/commands/tablebackgroundcolorcommand.js +14 -20
- package/src/tableproperties/commands/tablebordercolorcommand.d.ts +42 -0
- package/src/tableproperties/commands/tablebordercolorcommand.js +27 -37
- package/src/tableproperties/commands/tableborderstylecommand.d.ts +42 -0
- package/src/tableproperties/commands/tableborderstylecommand.js +27 -37
- package/src/tableproperties/commands/tableborderwidthcommand.d.ts +56 -0
- package/src/tableproperties/commands/tableborderwidthcommand.js +42 -53
- package/src/tableproperties/commands/tableheightcommand.d.ts +51 -0
- package/src/tableproperties/commands/tableheightcommand.js +29 -33
- package/src/tableproperties/commands/tablepropertycommand.d.ts +61 -0
- package/src/tableproperties/commands/tablepropertycommand.js +68 -112
- package/src/tableproperties/commands/tablewidthcommand.d.ts +51 -0
- package/src/tableproperties/commands/tablewidthcommand.js +29 -33
- package/src/tableproperties/tablepropertiesediting.d.ts +45 -0
- package/src/tableproperties/tablepropertiesediting.js +164 -210
- package/src/tableproperties/tablepropertiesui.d.ts +119 -0
- package/src/tableproperties/tablepropertiesui.js +294 -439
- package/src/tableproperties/ui/tablepropertiesview.d.ts +203 -0
- package/src/tableproperties/ui/tablepropertiesview.js +427 -718
- package/src/tableproperties.d.ts +33 -0
- package/src/tableproperties.js +12 -95
- package/src/tableselection.d.ts +111 -0
- package/src/tableselection.js +279 -376
- package/src/tabletoolbar.d.ts +37 -0
- package/src/tabletoolbar.js +39 -92
- package/src/tableui.d.ts +58 -0
- package/src/tableui.js +281 -338
- package/src/tableutils.d.ts +453 -0
- package/src/tableutils.js +1015 -1229
- package/src/tablewalker.d.ts +323 -0
- package/src/tablewalker.js +308 -548
- package/src/ui/colorinputview.d.ts +143 -0
- package/src/ui/colorinputview.js +229 -366
- package/src/ui/formrowview.d.ts +61 -0
- package/src/ui/formrowview.js +38 -84
- package/src/ui/inserttableview.d.ts +77 -0
- package/src/ui/inserttableview.js +152 -242
- package/src/utils/common.d.ts +42 -0
- package/src/utils/common.js +33 -57
- package/src/utils/structure.d.ts +245 -0
- package/src/utils/structure.js +261 -379
- package/src/utils/table-properties.d.ts +67 -0
- package/src/utils/table-properties.js +60 -81
- package/src/utils/ui/contextualballoon.d.ts +34 -0
- package/src/utils/ui/contextualballoon.js +70 -89
- package/src/utils/ui/table-properties.d.ts +193 -0
- package/src/utils/ui/table-properties.js +259 -319
- package/src/utils/ui/widget.d.ts +16 -0
- package/src/utils/ui/widget.js +24 -46
- package/src/tablecolumnresize/tablecolumnwidthscommand.js +0 -55
- package/src/tablecolumnresize/tablewidthresizecommand.js +0 -65
package/src/utils/structure.js
CHANGED
|
@@ -2,318 +2,241 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @module table/utils/structure
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import TableWalker from '../tablewalker';
|
|
5
|
+
import { default as TableWalker } from '../tablewalker';
|
|
11
6
|
import { createEmptyTableCell, updateNumericAttribute } from './common';
|
|
12
|
-
|
|
13
7
|
/**
|
|
14
8
|
* Returns a cropped table according to given dimensions.
|
|
15
9
|
|
|
16
10
|
* To return a cropped table that starts at first row and first column and end in third row and column:
|
|
17
11
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const croppedTable = cropTableToDimensions( table, {
|
|
14
|
+
* startRow: 1,
|
|
15
|
+
* endRow: 3,
|
|
16
|
+
* startColumn: 1,
|
|
17
|
+
* endColumn: 3
|
|
18
|
+
* }, writer );
|
|
19
|
+
* ```
|
|
24
20
|
*
|
|
25
21
|
* Calling the code above for the table below:
|
|
26
22
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @param {module:engine/model/element~Element} sourceTable
|
|
41
|
-
* @param {Object} cropDimensions
|
|
42
|
-
* @param {Number} cropDimensions.startRow
|
|
43
|
-
* @param {Number} cropDimensions.startColumn
|
|
44
|
-
* @param {Number} cropDimensions.endRow
|
|
45
|
-
* @param {Number} cropDimensions.endColumn
|
|
46
|
-
* @param {module:engine/model/writer~Writer} writer
|
|
47
|
-
* @returns {module:engine/model/element~Element}
|
|
23
|
+
* 0 1 2 3 4 0 1 2
|
|
24
|
+
* ┌───┬───┬───┬───┬───┐
|
|
25
|
+
* 0 │ a │ b │ c │ d │ e │
|
|
26
|
+
* ├───┴───┤ ├───┴───┤ ┌───┬───┬───┐
|
|
27
|
+
* 1 │ f │ │ g │ │ │ │ g │ 0
|
|
28
|
+
* ├───┬───┴───┼───┬───┤ will return: ├───┴───┼───┤
|
|
29
|
+
* 2 │ h │ i │ j │ k │ │ i │ j │ 1
|
|
30
|
+
* ├───┤ ├───┤ │ │ ├───┤
|
|
31
|
+
* 3 │ l │ │ m │ │ │ │ m │ 2
|
|
32
|
+
* ├───┼───┬───┤ ├───┤ └───────┴───┘
|
|
33
|
+
* 4 │ n │ o │ p │ │ q │
|
|
34
|
+
* └───┴───┴───┴───┴───┘
|
|
48
35
|
*/
|
|
49
|
-
export function cropTableToDimensions(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// In the table from method jsdoc those cells are: "g" & "m".
|
|
84
|
-
trimTableCellIfNeeded( tableCellCopy, sourceRow, sourceColumn, endRow, endColumn, writer );
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Adjust heading rows & columns in cropped table if crop selection includes headings parts.
|
|
89
|
-
addHeadingsToCroppedTable( croppedTable, sourceTable, startRow, startColumn, writer );
|
|
90
|
-
|
|
91
|
-
return croppedTable;
|
|
36
|
+
export function cropTableToDimensions(sourceTable, cropDimensions, writer) {
|
|
37
|
+
const { startRow, startColumn, endRow, endColumn } = cropDimensions;
|
|
38
|
+
// Create empty table with empty rows equal to crop height.
|
|
39
|
+
const croppedTable = writer.createElement('table');
|
|
40
|
+
const cropHeight = endRow - startRow + 1;
|
|
41
|
+
for (let i = 0; i < cropHeight; i++) {
|
|
42
|
+
writer.insertElement('tableRow', croppedTable, 'end');
|
|
43
|
+
}
|
|
44
|
+
const tableMap = [...new TableWalker(sourceTable, { startRow, endRow, startColumn, endColumn, includeAllSlots: true })];
|
|
45
|
+
// Iterate over source table slots (including empty - spanned - ones).
|
|
46
|
+
for (const { row: sourceRow, column: sourceColumn, cell: tableCell, isAnchor, cellAnchorRow, cellAnchorColumn } of tableMap) {
|
|
47
|
+
// Row index in cropped table.
|
|
48
|
+
const rowInCroppedTable = sourceRow - startRow;
|
|
49
|
+
const row = croppedTable.getChild(rowInCroppedTable);
|
|
50
|
+
// For empty slots: fill the gap with empty table cell.
|
|
51
|
+
if (!isAnchor) {
|
|
52
|
+
// But fill the gap only if the spanning cell is anchored outside cropped area.
|
|
53
|
+
// In the table from method jsdoc those cells are: "c" & "f".
|
|
54
|
+
if (cellAnchorRow < startRow || cellAnchorColumn < startColumn) {
|
|
55
|
+
createEmptyTableCell(writer, writer.createPositionAt(row, 'end'));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Otherwise clone the cell with all children and trim if it exceeds cropped area.
|
|
59
|
+
else {
|
|
60
|
+
const tableCellCopy = writer.cloneElement(tableCell);
|
|
61
|
+
writer.append(tableCellCopy, row);
|
|
62
|
+
// Trim table if it exceeds cropped area.
|
|
63
|
+
// In the table from method jsdoc those cells are: "g" & "m".
|
|
64
|
+
trimTableCellIfNeeded(tableCellCopy, sourceRow, sourceColumn, endRow, endColumn, writer);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Adjust heading rows & columns in cropped table if crop selection includes headings parts.
|
|
68
|
+
addHeadingsToCroppedTable(croppedTable, sourceTable, startRow, startColumn, writer);
|
|
69
|
+
return croppedTable;
|
|
92
70
|
}
|
|
93
|
-
|
|
94
71
|
/**
|
|
95
72
|
* Returns slot info of cells that starts above and overlaps a given row.
|
|
96
73
|
*
|
|
97
74
|
* In a table below, passing `overlapRow = 3`
|
|
98
75
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
76
|
+
* ┌───┬───┬───┬───┬───┐
|
|
77
|
+
* 0 │ a │ b │ c │ d │ e │
|
|
78
|
+
* │ ├───┼───┼───┼───┤
|
|
79
|
+
* 1 │ │ f │ g │ h │ i │
|
|
80
|
+
* ├───┤ ├───┼───┤ │
|
|
81
|
+
* 2 │ j │ │ k │ l │ │
|
|
82
|
+
* │ │ │ ├───┼───┤
|
|
83
|
+
* 3 │ │ │ │ m │ n │ <- overlap row to check
|
|
84
|
+
* ├───┼───┤ │ ├───│
|
|
85
|
+
* 4 │ o │ p │ │ │ q │
|
|
86
|
+
* └───┴───┴───┴───┴───┘
|
|
110
87
|
*
|
|
111
88
|
* will return slot info for cells: "j", "f", "k".
|
|
112
89
|
*
|
|
113
|
-
* @param
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
116
|
-
* @returns {Array.<module:table/tablewalker~TableSlot>}
|
|
90
|
+
* @param table The table to check.
|
|
91
|
+
* @param overlapRow The index of the row to check.
|
|
92
|
+
* @param startRow row to start analysis. Use it when it is known that the cells above that row will not overlap. Default value is 0.
|
|
117
93
|
*/
|
|
118
|
-
export function getVerticallyOverlappingCells(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return cells;
|
|
94
|
+
export function getVerticallyOverlappingCells(table, overlapRow, startRow = 0) {
|
|
95
|
+
const cells = [];
|
|
96
|
+
const tableWalker = new TableWalker(table, { startRow, endRow: overlapRow - 1 });
|
|
97
|
+
for (const slotInfo of tableWalker) {
|
|
98
|
+
const { row, cellHeight } = slotInfo;
|
|
99
|
+
const cellEndRow = row + cellHeight - 1;
|
|
100
|
+
if (row < overlapRow && overlapRow <= cellEndRow) {
|
|
101
|
+
cells.push(slotInfo);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return cells;
|
|
133
105
|
}
|
|
134
|
-
|
|
135
106
|
/**
|
|
136
107
|
* Splits the table cell horizontally.
|
|
137
108
|
*
|
|
138
|
-
* @
|
|
139
|
-
* @param {Number} splitRow
|
|
140
|
-
* @param {module:engine/model/writer~Writer} writer
|
|
141
|
-
* @returns {module:engine/model/element~Element} Created table cell.
|
|
109
|
+
* @returns Created table cell, if any were created.
|
|
142
110
|
*/
|
|
143
|
-
export function splitHorizontally(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
columnIndex = column;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if ( columnIndex !== undefined && columnIndex === column && row === endRow ) {
|
|
179
|
-
newCell = createEmptyTableCell( writer, tableSlot.getPositionBefore(), newCellAttributes );
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Update the rowspan attribute after updating table.
|
|
184
|
-
updateNumericAttribute( 'rowspan', newRowspan, tableCell, writer );
|
|
185
|
-
|
|
186
|
-
return newCell;
|
|
111
|
+
export function splitHorizontally(tableCell, splitRow, writer) {
|
|
112
|
+
const tableRow = tableCell.parent;
|
|
113
|
+
const table = tableRow.parent;
|
|
114
|
+
const rowIndex = tableRow.index;
|
|
115
|
+
const rowspan = parseInt(tableCell.getAttribute('rowspan'));
|
|
116
|
+
const newRowspan = splitRow - rowIndex;
|
|
117
|
+
const newCellAttributes = {};
|
|
118
|
+
const newCellRowSpan = rowspan - newRowspan;
|
|
119
|
+
if (newCellRowSpan > 1) {
|
|
120
|
+
newCellAttributes.rowspan = newCellRowSpan;
|
|
121
|
+
}
|
|
122
|
+
const colspan = parseInt(tableCell.getAttribute('colspan') || '1');
|
|
123
|
+
if (colspan > 1) {
|
|
124
|
+
newCellAttributes.colspan = colspan;
|
|
125
|
+
}
|
|
126
|
+
const startRow = rowIndex;
|
|
127
|
+
const endRow = startRow + newRowspan;
|
|
128
|
+
const tableMap = [...new TableWalker(table, { startRow, endRow, includeAllSlots: true })];
|
|
129
|
+
let newCell = null;
|
|
130
|
+
let columnIndex;
|
|
131
|
+
for (const tableSlot of tableMap) {
|
|
132
|
+
const { row, column, cell } = tableSlot;
|
|
133
|
+
if (cell === tableCell && columnIndex === undefined) {
|
|
134
|
+
columnIndex = column;
|
|
135
|
+
}
|
|
136
|
+
if (columnIndex !== undefined && columnIndex === column && row === endRow) {
|
|
137
|
+
newCell = createEmptyTableCell(writer, tableSlot.getPositionBefore(), newCellAttributes);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Update the rowspan attribute after updating table.
|
|
141
|
+
updateNumericAttribute('rowspan', newRowspan, tableCell, writer);
|
|
142
|
+
return newCell;
|
|
187
143
|
}
|
|
188
|
-
|
|
189
144
|
/**
|
|
190
145
|
* Returns slot info of cells that starts before and overlaps a given column.
|
|
191
146
|
*
|
|
192
147
|
* In a table below, passing `overlapColumn = 3`
|
|
193
148
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
149
|
+
* 0 1 2 3 4
|
|
150
|
+
* ┌───────┬───────┬───┐
|
|
151
|
+
* │ a │ b │ c │
|
|
152
|
+
* │───┬───┴───────┼───┤
|
|
153
|
+
* │ d │ e │ f │
|
|
154
|
+
* ├───┼───┬───────┴───┤
|
|
155
|
+
* │ g │ h │ i │
|
|
156
|
+
* ├───┼───┼───┬───────┤
|
|
157
|
+
* │ j │ k │ l │ m │
|
|
158
|
+
* ├───┼───┴───┼───┬───┤
|
|
159
|
+
* │ n │ o │ p │ q │
|
|
160
|
+
* └───┴───────┴───┴───┘
|
|
161
|
+
* ^
|
|
162
|
+
* Overlap column to check
|
|
208
163
|
*
|
|
209
164
|
* will return slot info for cells: "b", "e", "i".
|
|
210
165
|
*
|
|
211
|
-
* @param
|
|
212
|
-
* @param
|
|
213
|
-
* @returns {Array.<module:table/tablewalker~TableSlot>}
|
|
166
|
+
* @param table The table to check.
|
|
167
|
+
* @param overlapColumn The index of the column to check.
|
|
214
168
|
*/
|
|
215
|
-
export function getHorizontallyOverlappingCells(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return cellsToSplit;
|
|
169
|
+
export function getHorizontallyOverlappingCells(table, overlapColumn) {
|
|
170
|
+
const cellsToSplit = [];
|
|
171
|
+
const tableWalker = new TableWalker(table);
|
|
172
|
+
for (const slotInfo of tableWalker) {
|
|
173
|
+
const { column, cellWidth } = slotInfo;
|
|
174
|
+
const cellEndColumn = column + cellWidth - 1;
|
|
175
|
+
if (column < overlapColumn && overlapColumn <= cellEndColumn) {
|
|
176
|
+
cellsToSplit.push(slotInfo);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return cellsToSplit;
|
|
230
180
|
}
|
|
231
|
-
|
|
232
181
|
/**
|
|
233
182
|
* Splits the table cell vertically.
|
|
234
183
|
*
|
|
235
|
-
* @param
|
|
236
|
-
* @param
|
|
237
|
-
* @
|
|
238
|
-
* @param {module:engine/model/writer~Writer} writer
|
|
239
|
-
* @returns {module:engine/model/element~Element} Created table cell.
|
|
184
|
+
* @param columnIndex The table cell column index.
|
|
185
|
+
* @param splitColumn The index of column to split cell on.
|
|
186
|
+
* @returns Created table cell.
|
|
240
187
|
*/
|
|
241
|
-
export function splitVertically(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const newCell = createEmptyTableCell( writer, writer.createPositionAfter( tableCell ), newCellAttributes );
|
|
259
|
-
|
|
260
|
-
// Update the colspan attribute after updating table.
|
|
261
|
-
updateNumericAttribute( 'colspan', newColspan, tableCell, writer );
|
|
262
|
-
|
|
263
|
-
return newCell;
|
|
188
|
+
export function splitVertically(tableCell, columnIndex, splitColumn, writer) {
|
|
189
|
+
const colspan = parseInt(tableCell.getAttribute('colspan'));
|
|
190
|
+
const newColspan = splitColumn - columnIndex;
|
|
191
|
+
const newCellAttributes = {};
|
|
192
|
+
const newCellColSpan = colspan - newColspan;
|
|
193
|
+
if (newCellColSpan > 1) {
|
|
194
|
+
newCellAttributes.colspan = newCellColSpan;
|
|
195
|
+
}
|
|
196
|
+
const rowspan = parseInt(tableCell.getAttribute('rowspan') || '1');
|
|
197
|
+
if (rowspan > 1) {
|
|
198
|
+
newCellAttributes.rowspan = rowspan;
|
|
199
|
+
}
|
|
200
|
+
const newCell = createEmptyTableCell(writer, writer.createPositionAfter(tableCell), newCellAttributes);
|
|
201
|
+
// Update the colspan attribute after updating table.
|
|
202
|
+
updateNumericAttribute('colspan', newColspan, tableCell, writer);
|
|
203
|
+
return newCell;
|
|
264
204
|
}
|
|
265
|
-
|
|
266
205
|
/**
|
|
267
206
|
* Adjusts table cell dimensions to not exceed limit row and column.
|
|
268
207
|
*
|
|
269
208
|
* If table cell width (or height) covers a column (or row) that is after a limit column (or row)
|
|
270
209
|
* this method will trim "colspan" (or "rowspan") attribute so the table cell will fit in a defined limits.
|
|
271
|
-
*
|
|
272
|
-
* @param {module:engine/model/element~Element} tableCell
|
|
273
|
-
* @param {Number} cellRow
|
|
274
|
-
* @param {Number} cellColumn
|
|
275
|
-
* @param {Number} limitRow
|
|
276
|
-
* @param {Number} limitColumn
|
|
277
|
-
* @param {module:engine/model/writer~Writer} writer
|
|
278
210
|
*/
|
|
279
|
-
export function trimTableCellIfNeeded(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if ( endRow > limitRow ) {
|
|
294
|
-
const trimmedSpan = limitRow - cellRow + 1;
|
|
295
|
-
|
|
296
|
-
updateNumericAttribute( 'rowspan', trimmedSpan, tableCell, writer, 1 );
|
|
297
|
-
}
|
|
211
|
+
export function trimTableCellIfNeeded(tableCell, cellRow, cellColumn, limitRow, limitColumn, writer) {
|
|
212
|
+
const colspan = parseInt(tableCell.getAttribute('colspan') || '1');
|
|
213
|
+
const rowspan = parseInt(tableCell.getAttribute('rowspan') || '1');
|
|
214
|
+
const endColumn = cellColumn + colspan - 1;
|
|
215
|
+
if (endColumn > limitColumn) {
|
|
216
|
+
const trimmedSpan = limitColumn - cellColumn + 1;
|
|
217
|
+
updateNumericAttribute('colspan', trimmedSpan, tableCell, writer, 1);
|
|
218
|
+
}
|
|
219
|
+
const endRow = cellRow + rowspan - 1;
|
|
220
|
+
if (endRow > limitRow) {
|
|
221
|
+
const trimmedSpan = limitRow - cellRow + 1;
|
|
222
|
+
updateNumericAttribute('rowspan', trimmedSpan, tableCell, writer, 1);
|
|
223
|
+
}
|
|
298
224
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
updateNumericAttribute( 'headingColumns', headingColumnsInCrop, croppedTable, writer, 0 );
|
|
314
|
-
}
|
|
225
|
+
/**
|
|
226
|
+
* Sets proper heading attributes to a cropped table.
|
|
227
|
+
*/
|
|
228
|
+
function addHeadingsToCroppedTable(croppedTable, sourceTable, startRow, startColumn, writer) {
|
|
229
|
+
const headingRows = parseInt(sourceTable.getAttribute('headingRows') || '0');
|
|
230
|
+
if (headingRows > 0) {
|
|
231
|
+
const headingRowsInCrop = headingRows - startRow;
|
|
232
|
+
updateNumericAttribute('headingRows', headingRowsInCrop, croppedTable, writer, 0);
|
|
233
|
+
}
|
|
234
|
+
const headingColumns = parseInt(sourceTable.getAttribute('headingColumns') || '0');
|
|
235
|
+
if (headingColumns > 0) {
|
|
236
|
+
const headingColumnsInCrop = headingColumns - startColumn;
|
|
237
|
+
updateNumericAttribute('headingColumns', headingColumnsInCrop, croppedTable, writer, 0);
|
|
238
|
+
}
|
|
315
239
|
}
|
|
316
|
-
|
|
317
240
|
/**
|
|
318
241
|
* Removes columns that have no cells anchored.
|
|
319
242
|
*
|
|
@@ -333,36 +256,27 @@ function addHeadingsToCroppedTable( croppedTable, sourceTable, startRow, startCo
|
|
|
333
256
|
* **Note:** This is a low-level helper method for clearing invalid model state when doing table modifications.
|
|
334
257
|
* To remove a column from a table use {@link module:table/tableutils~TableUtils#removeColumns `TableUtils.removeColumns()`}.
|
|
335
258
|
*
|
|
336
|
-
* @
|
|
337
|
-
* @
|
|
338
|
-
* @param {module:table/tableutils~TableUtils} tableUtils
|
|
339
|
-
* @returns {Boolean} True if removed some columns.
|
|
259
|
+
* @internal
|
|
260
|
+
* @returns True if removed some columns.
|
|
340
261
|
*/
|
|
341
|
-
export function removeEmptyColumns(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
tableUtils.removeColumns( table, { at: emptyColumn } );
|
|
359
|
-
|
|
360
|
-
return true;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return false;
|
|
262
|
+
export function removeEmptyColumns(table, tableUtils) {
|
|
263
|
+
const width = tableUtils.getColumns(table);
|
|
264
|
+
const columnsMap = new Array(width).fill(0);
|
|
265
|
+
for (const { column } of new TableWalker(table)) {
|
|
266
|
+
columnsMap[column]++;
|
|
267
|
+
}
|
|
268
|
+
const emptyColumns = columnsMap.reduce((result, cellsCount, column) => {
|
|
269
|
+
return cellsCount ? result : [...result, column];
|
|
270
|
+
}, []);
|
|
271
|
+
if (emptyColumns.length > 0) {
|
|
272
|
+
// Remove only last empty column because it will recurrently trigger removing empty rows.
|
|
273
|
+
const emptyColumn = emptyColumns[emptyColumns.length - 1];
|
|
274
|
+
// @if CK_DEBUG_TABLE // console.log( `Removing empty column: ${ emptyColumn }.` );
|
|
275
|
+
tableUtils.removeColumns(table, { at: emptyColumn });
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
364
279
|
}
|
|
365
|
-
|
|
366
280
|
/**
|
|
367
281
|
* Removes rows that have no cells anchored.
|
|
368
282
|
*
|
|
@@ -389,36 +303,27 @@ export function removeEmptyColumns( table, tableUtils ) {
|
|
|
389
303
|
* **Note:** This is a low-level helper method for clearing invalid model state when doing table modifications.
|
|
390
304
|
* To remove a row from a table use {@link module:table/tableutils~TableUtils#removeRows `TableUtils.removeRows()`}.
|
|
391
305
|
*
|
|
392
|
-
* @
|
|
393
|
-
* @
|
|
394
|
-
* @param {module:table/tableutils~TableUtils} tableUtils
|
|
395
|
-
* @returns {Boolean} True if removed some rows.
|
|
306
|
+
* @internal
|
|
307
|
+
* @returns True if removed some rows.
|
|
396
308
|
*/
|
|
397
|
-
export function removeEmptyRows(
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
tableUtils.removeRows( table, { at: emptyRow } );
|
|
415
|
-
|
|
416
|
-
return true;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
return false;
|
|
309
|
+
export function removeEmptyRows(table, tableUtils) {
|
|
310
|
+
const emptyRows = [];
|
|
311
|
+
const tableRowCount = tableUtils.getRows(table);
|
|
312
|
+
for (let rowIndex = 0; rowIndex < tableRowCount; rowIndex++) {
|
|
313
|
+
const tableRow = table.getChild(rowIndex);
|
|
314
|
+
if (tableRow.isEmpty) {
|
|
315
|
+
emptyRows.push(rowIndex);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (emptyRows.length > 0) {
|
|
319
|
+
// Remove only last empty row because it will recurrently trigger removing empty columns.
|
|
320
|
+
const emptyRow = emptyRows[emptyRows.length - 1];
|
|
321
|
+
// @if CK_DEBUG_TABLE // console.log( `Removing empty row: ${ emptyRow }.` );
|
|
322
|
+
tableUtils.removeRows(table, { at: emptyRow });
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
return false;
|
|
420
326
|
}
|
|
421
|
-
|
|
422
327
|
/**
|
|
423
328
|
* Removes rows and columns that have no cells anchored.
|
|
424
329
|
*
|
|
@@ -441,19 +346,15 @@ export function removeEmptyRows( table, tableUtils ) {
|
|
|
441
346
|
* To remove a rows from a table use {@link module:table/tableutils~TableUtils#removeRows `TableUtils.removeRows()`} and
|
|
442
347
|
* {@link module:table/tableutils~TableUtils#removeColumns `TableUtils.removeColumns()`} to remove a column.
|
|
443
348
|
*
|
|
444
|
-
* @
|
|
445
|
-
* @param {module:engine/model/element~Element} table
|
|
446
|
-
* @param {module:table/tableutils~TableUtils} tableUtils
|
|
349
|
+
* @internal
|
|
447
350
|
*/
|
|
448
|
-
export function removeEmptyRowsColumns(
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
351
|
+
export function removeEmptyRowsColumns(table, tableUtils) {
|
|
352
|
+
const removedColumns = removeEmptyColumns(table, tableUtils);
|
|
353
|
+
// If there was some columns removed then cleaning empty rows was already triggered.
|
|
354
|
+
if (!removedColumns) {
|
|
355
|
+
removeEmptyRows(table, tableUtils);
|
|
356
|
+
}
|
|
455
357
|
}
|
|
456
|
-
|
|
457
358
|
/**
|
|
458
359
|
* Returns adjusted last row index if selection covers part of a row with empty slots (spanned by other cells).
|
|
459
360
|
* The `dimensions.lastRow` is equal to last row index but selection might be bigger.
|
|
@@ -470,33 +371,23 @@ export function removeEmptyRowsColumns( table, tableUtils ) {
|
|
|
470
371
|
* 3 | | | | |
|
|
471
372
|
* +---+---+---+---+
|
|
472
373
|
*
|
|
473
|
-
* @
|
|
474
|
-
* @param {Object} dimensions
|
|
475
|
-
* @param {Number} dimensions.firstRow
|
|
476
|
-
* @param {Number} dimensions.firstColumn
|
|
477
|
-
* @param {Number} dimensions.lastRow
|
|
478
|
-
* @param {Number} dimensions.lastColumn
|
|
479
|
-
* @returns {Number} Adjusted last row index.
|
|
374
|
+
* @returns Adjusted last row index.
|
|
480
375
|
*/
|
|
481
|
-
export function adjustLastRowIndex(
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
// Otherwise get any cell's rowspan and adjust the last row index.
|
|
496
|
-
const rowspanAdjustment = lastRowMap[ 0 ].cellHeight - 1;
|
|
497
|
-
return dimensions.lastRow + rowspanAdjustment;
|
|
376
|
+
export function adjustLastRowIndex(table, dimensions) {
|
|
377
|
+
const lastRowMap = Array.from(new TableWalker(table, {
|
|
378
|
+
startColumn: dimensions.firstColumn,
|
|
379
|
+
endColumn: dimensions.lastColumn,
|
|
380
|
+
row: dimensions.lastRow
|
|
381
|
+
}));
|
|
382
|
+
const everyCellHasSingleRowspan = lastRowMap.every(({ cellHeight }) => cellHeight === 1);
|
|
383
|
+
// It is a "flat" row, so the last row index is OK.
|
|
384
|
+
if (everyCellHasSingleRowspan) {
|
|
385
|
+
return dimensions.lastRow;
|
|
386
|
+
}
|
|
387
|
+
// Otherwise get any cell's rowspan and adjust the last row index.
|
|
388
|
+
const rowspanAdjustment = lastRowMap[0].cellHeight - 1;
|
|
389
|
+
return dimensions.lastRow + rowspanAdjustment;
|
|
498
390
|
}
|
|
499
|
-
|
|
500
391
|
/**
|
|
501
392
|
* Returns adjusted last column index if selection covers part of a column with empty slots (spanned by other cells).
|
|
502
393
|
* The `dimensions.lastColumn` is equal to last column index but selection might be bigger.
|
|
@@ -516,29 +407,20 @@ export function adjustLastRowIndex( table, dimensions ) {
|
|
|
516
407
|
* ^
|
|
517
408
|
* last column, each cell has colspan = 2, so we need to return 3, not 2
|
|
518
409
|
*
|
|
519
|
-
* @
|
|
520
|
-
* @param {Object} dimensions
|
|
521
|
-
* @param {Number} dimensions.firstRow
|
|
522
|
-
* @param {Number} dimensions.firstColumn
|
|
523
|
-
* @param {Number} dimensions.lastRow
|
|
524
|
-
* @param {Number} dimensions.lastColumn
|
|
525
|
-
* @returns {Number} Adjusted last column index.
|
|
410
|
+
* @returns Adjusted last column index.
|
|
526
411
|
*/
|
|
527
|
-
export function adjustLastColumnIndex(
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
// Otherwise get any cell's colspan and adjust the last column index.
|
|
542
|
-
const colspanAdjustment = lastColumnMap[ 0 ].cellWidth - 1;
|
|
543
|
-
return dimensions.lastColumn + colspanAdjustment;
|
|
412
|
+
export function adjustLastColumnIndex(table, dimensions) {
|
|
413
|
+
const lastColumnMap = Array.from(new TableWalker(table, {
|
|
414
|
+
startRow: dimensions.firstRow,
|
|
415
|
+
endRow: dimensions.lastRow,
|
|
416
|
+
column: dimensions.lastColumn
|
|
417
|
+
}));
|
|
418
|
+
const everyCellHasSingleColspan = lastColumnMap.every(({ cellWidth }) => cellWidth === 1);
|
|
419
|
+
// It is a "flat" column, so the last column index is OK.
|
|
420
|
+
if (everyCellHasSingleColspan) {
|
|
421
|
+
return dimensions.lastColumn;
|
|
422
|
+
}
|
|
423
|
+
// Otherwise get any cell's colspan and adjust the last column index.
|
|
424
|
+
const colspanAdjustment = lastColumnMap[0].cellWidth - 1;
|
|
425
|
+
return dimensions.lastColumn + colspanAdjustment;
|
|
544
426
|
}
|