@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
|
@@ -2,16 +2,10 @@
|
|
|
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/commands/mergecellscommand
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
5
|
import { Command } from 'ckeditor5/src/core';
|
|
11
6
|
import TableUtils from '../tableutils';
|
|
12
7
|
import { updateNumericAttribute } from '../utils/common';
|
|
13
8
|
import { removeEmptyRowsColumns } from '../utils/structure';
|
|
14
|
-
|
|
15
9
|
/**
|
|
16
10
|
* The merge cells command.
|
|
17
11
|
*
|
|
@@ -19,105 +13,82 @@ import { removeEmptyRowsColumns } from '../utils/structure';
|
|
|
19
13
|
*
|
|
20
14
|
* For example, to merge selected table cells:
|
|
21
15
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* editor.execute( 'mergeTableCells' );
|
|
18
|
+
* ```
|
|
25
19
|
*/
|
|
26
20
|
export default class MergeCellsCommand extends Command {
|
|
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
|
-
const table = firstTableCell.findAncestor( 'table' );
|
|
62
|
-
|
|
63
|
-
// Remove rows and columns that become empty (have no anchored cells).
|
|
64
|
-
removeEmptyRowsColumns( table, tableUtils );
|
|
65
|
-
|
|
66
|
-
writer.setSelection( firstTableCell, 'in' );
|
|
67
|
-
} );
|
|
68
|
-
}
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
refresh() {
|
|
25
|
+
const tableUtils = this.editor.plugins.get(TableUtils);
|
|
26
|
+
const selectedTableCells = tableUtils.getSelectedTableCells(this.editor.model.document.selection);
|
|
27
|
+
this.isEnabled = tableUtils.isSelectionRectangular(selectedTableCells);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Executes the command.
|
|
31
|
+
*
|
|
32
|
+
* @fires execute
|
|
33
|
+
*/
|
|
34
|
+
execute() {
|
|
35
|
+
const model = this.editor.model;
|
|
36
|
+
const tableUtils = this.editor.plugins.get(TableUtils);
|
|
37
|
+
model.change(writer => {
|
|
38
|
+
const selectedTableCells = tableUtils.getSelectedTableCells(model.document.selection);
|
|
39
|
+
// All cells will be merged into the first one.
|
|
40
|
+
const firstTableCell = selectedTableCells.shift();
|
|
41
|
+
// Update target cell dimensions.
|
|
42
|
+
const { mergeWidth, mergeHeight } = getMergeDimensions(firstTableCell, selectedTableCells, tableUtils);
|
|
43
|
+
updateNumericAttribute('colspan', mergeWidth, firstTableCell, writer);
|
|
44
|
+
updateNumericAttribute('rowspan', mergeHeight, firstTableCell, writer);
|
|
45
|
+
for (const tableCell of selectedTableCells) {
|
|
46
|
+
mergeTableCells(tableCell, firstTableCell, writer);
|
|
47
|
+
}
|
|
48
|
+
const table = firstTableCell.findAncestor('table');
|
|
49
|
+
// Remove rows and columns that become empty (have no anchored cells).
|
|
50
|
+
removeEmptyRowsColumns(table, tableUtils);
|
|
51
|
+
writer.setSelection(firstTableCell, 'in');
|
|
52
|
+
});
|
|
53
|
+
}
|
|
69
54
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
writer.move( writer.createRangeIn( cellBeingMerged ), writer.createPositionAt( targetCell, 'end' ) );
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Remove merged table cell.
|
|
88
|
-
writer.remove( cellBeingMerged );
|
|
55
|
+
/**
|
|
56
|
+
* Merges two table cells. It will ensure that after merging cells with empty paragraphs the resulting table cell will only have one
|
|
57
|
+
* paragraph. If one of the merged table cells is empty, the merged table cell will have contents of the non-empty table cell.
|
|
58
|
+
* If both are empty, the merged table cell will have only one empty paragraph.
|
|
59
|
+
*/
|
|
60
|
+
function mergeTableCells(cellBeingMerged, targetCell, writer) {
|
|
61
|
+
if (!isEmpty(cellBeingMerged)) {
|
|
62
|
+
if (isEmpty(targetCell)) {
|
|
63
|
+
writer.remove(writer.createRangeIn(targetCell));
|
|
64
|
+
}
|
|
65
|
+
writer.move(writer.createRangeIn(cellBeingMerged), writer.createPositionAt(targetCell, 'end'));
|
|
66
|
+
}
|
|
67
|
+
// Remove merged table cell.
|
|
68
|
+
writer.remove(cellBeingMerged);
|
|
89
69
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return tableCell.childCount == 1 && tableCell.getChild( 0 ).is( 'element', 'paragraph' ) && tableCell.getChild( 0 ).isEmpty;
|
|
70
|
+
/**
|
|
71
|
+
* Checks if the passed table cell contains an empty paragraph.
|
|
72
|
+
*/
|
|
73
|
+
function isEmpty(tableCell) {
|
|
74
|
+
const firstTableChild = tableCell.getChild(0);
|
|
75
|
+
return tableCell.childCount == 1 && firstTableChild.is('element', 'paragraph') && firstTableChild.isEmpty;
|
|
97
76
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const { row: firstCellRow, column: firstCellColumn } = tableUtils.getCellLocation( firstTableCell );
|
|
112
|
-
|
|
113
|
-
const mergeWidth = maxWidthOffset - firstCellColumn;
|
|
114
|
-
const mergeHeight = maxHeightOffset - firstCellRow;
|
|
115
|
-
|
|
116
|
-
return { mergeWidth, mergeHeight };
|
|
77
|
+
function getMergeDimensions(firstTableCell, selectedTableCells, tableUtils) {
|
|
78
|
+
let maxWidthOffset = 0;
|
|
79
|
+
let maxHeightOffset = 0;
|
|
80
|
+
for (const tableCell of selectedTableCells) {
|
|
81
|
+
const { row, column } = tableUtils.getCellLocation(tableCell);
|
|
82
|
+
maxWidthOffset = getMaxOffset(tableCell, column, maxWidthOffset, 'colspan');
|
|
83
|
+
maxHeightOffset = getMaxOffset(tableCell, row, maxHeightOffset, 'rowspan');
|
|
84
|
+
}
|
|
85
|
+
// Update table cell span attribute and merge set selection on a merged contents.
|
|
86
|
+
const { row: firstCellRow, column: firstCellColumn } = tableUtils.getCellLocation(firstTableCell);
|
|
87
|
+
const mergeWidth = maxWidthOffset - firstCellColumn;
|
|
88
|
+
const mergeHeight = maxHeightOffset - firstCellRow;
|
|
89
|
+
return { mergeWidth, mergeHeight };
|
|
117
90
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return Math.max( currentMaxOffset, start + dimensionValue );
|
|
91
|
+
function getMaxOffset(tableCell, start, currentMaxOffset, which) {
|
|
92
|
+
const dimensionValue = parseInt(tableCell.getAttribute(which) || '1');
|
|
93
|
+
return Math.max(currentMaxOffset, start + dimensionValue);
|
|
123
94
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module table/commands/removecolumncommand
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from 'ckeditor5/src/core';
|
|
9
|
+
/**
|
|
10
|
+
* The remove column command.
|
|
11
|
+
*
|
|
12
|
+
* The command is registered by {@link module:table/tableediting~TableEditing} as the `'removeTableColumn'` editor command.
|
|
13
|
+
*
|
|
14
|
+
* To remove the column containing the selected cell, execute the command:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* editor.execute( 'removeTableColumn' );
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export default class RemoveColumnCommand extends Command {
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
refresh(): void;
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
execute(): void;
|
|
29
|
+
}
|
|
30
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
31
|
+
interface CommandsMap {
|
|
32
|
+
removeTableColumn: RemoveColumnCommand;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -2,15 +2,11 @@
|
|
|
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
5
|
/**
|
|
7
6
|
* @module table/commands/removecolumncommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Command } from 'ckeditor5/src/core';
|
|
11
|
-
|
|
12
9
|
import TableWalker from '../tablewalker';
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* The remove column command.
|
|
16
12
|
*
|
|
@@ -18,106 +14,96 @@ import TableWalker from '../tablewalker';
|
|
|
18
14
|
*
|
|
19
15
|
* To remove the column containing the selected cell, execute the command:
|
|
20
16
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* editor.execute( 'removeTableColumn' );
|
|
19
|
+
* ```
|
|
24
20
|
*/
|
|
25
21
|
export default class RemoveColumnCommand extends Command {
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.editor.plugins.get( 'TableUtils' ).removeColumns( table, {
|
|
69
|
-
at: removedColumnIndexes.first,
|
|
70
|
-
columns: columnsToRemove
|
|
71
|
-
} );
|
|
72
|
-
|
|
73
|
-
writer.setSelection( writer.createPositionAt( cellToFocus, 0 ) );
|
|
74
|
-
} );
|
|
75
|
-
}
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
refresh() {
|
|
26
|
+
const tableUtils = this.editor.plugins.get('TableUtils');
|
|
27
|
+
const selectedCells = tableUtils.getSelectionAffectedTableCells(this.editor.model.document.selection);
|
|
28
|
+
const firstCell = selectedCells[0];
|
|
29
|
+
if (firstCell) {
|
|
30
|
+
const table = firstCell.findAncestor('table');
|
|
31
|
+
const tableColumnCount = tableUtils.getColumns(table);
|
|
32
|
+
const { first, last } = tableUtils.getColumnIndexes(selectedCells);
|
|
33
|
+
this.isEnabled = last - first < (tableColumnCount - 1);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.isEnabled = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @inheritDoc
|
|
41
|
+
*/
|
|
42
|
+
execute() {
|
|
43
|
+
const tableUtils = this.editor.plugins.get('TableUtils');
|
|
44
|
+
const [firstCell, lastCell] = getBoundaryCells(this.editor.model.document.selection, tableUtils);
|
|
45
|
+
const table = firstCell.parent.parent;
|
|
46
|
+
// Cache the table before removing or updating colspans.
|
|
47
|
+
const tableMap = [...new TableWalker(table)];
|
|
48
|
+
// Store column indexes of removed columns.
|
|
49
|
+
const removedColumnIndexes = {
|
|
50
|
+
first: tableMap.find(value => value.cell === firstCell).column,
|
|
51
|
+
last: tableMap.find(value => value.cell === lastCell).column
|
|
52
|
+
};
|
|
53
|
+
const cellToFocus = getCellToFocus(tableMap, firstCell, lastCell, removedColumnIndexes);
|
|
54
|
+
this.editor.model.change(writer => {
|
|
55
|
+
const columnsToRemove = removedColumnIndexes.last - removedColumnIndexes.first + 1;
|
|
56
|
+
tableUtils.removeColumns(table, {
|
|
57
|
+
at: removedColumnIndexes.first,
|
|
58
|
+
columns: columnsToRemove
|
|
59
|
+
});
|
|
60
|
+
writer.setSelection(writer.createPositionAt(cellToFocus, 0));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
76
63
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Returns a proper table cell to focus after removing a column.
|
|
66
|
+
* - selection is on last table cell it will return previous cell.
|
|
67
|
+
*/
|
|
68
|
+
function getCellToFocus(tableMap, firstCell, lastCell, removedColumnIndexes) {
|
|
69
|
+
const colspan = parseInt(lastCell.getAttribute('colspan') || '1');
|
|
70
|
+
// If the table cell is spanned over 2+ columns - it will be truncated so the selection should
|
|
71
|
+
// stay in that cell.
|
|
72
|
+
if (colspan > 1) {
|
|
73
|
+
return lastCell;
|
|
74
|
+
}
|
|
75
|
+
// Normally, look for the cell in the same row that precedes the first cell to put selection there ("column on the left").
|
|
76
|
+
// If the deleted column is the first column of the table, there will be no predecessor: use the cell
|
|
77
|
+
// from the column that follows then (also in the same row).
|
|
78
|
+
else if (firstCell.previousSibling || lastCell.nextSibling) {
|
|
79
|
+
return lastCell.nextSibling || firstCell.previousSibling;
|
|
80
|
+
}
|
|
81
|
+
// It can happen that table cells have no siblings in a row, for instance, when there are row spans
|
|
82
|
+
// in the table (in the previous row). Then just look for the closest cell that is in a column
|
|
83
|
+
// that will not be removed to put the selection there.
|
|
84
|
+
else {
|
|
85
|
+
// Look for any cell in a column that precedes the first removed column.
|
|
86
|
+
if (removedColumnIndexes.first) {
|
|
87
|
+
return tableMap.reverse().find(({ column }) => {
|
|
88
|
+
return column < removedColumnIndexes.first;
|
|
89
|
+
}).cell;
|
|
90
|
+
}
|
|
91
|
+
// If the first removed column is the first column of the table, then
|
|
92
|
+
// look for any cell that is in a column that follows the last removed column.
|
|
93
|
+
else {
|
|
94
|
+
return tableMap.reverse().find(({ column }) => {
|
|
95
|
+
return column > removedColumnIndexes.last;
|
|
96
|
+
}).cell;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
112
99
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return firstCell.isBefore( lastCell ) ? returnValue : returnValue.reverse();
|
|
100
|
+
/**
|
|
101
|
+
* Returns helper object returning the first and the last cell contained in given selection, based on DOM order.
|
|
102
|
+
*/
|
|
103
|
+
function getBoundaryCells(selection, tableUtils) {
|
|
104
|
+
const referenceCells = tableUtils.getSelectionAffectedTableCells(selection);
|
|
105
|
+
const firstCell = referenceCells[0];
|
|
106
|
+
const lastCell = referenceCells.pop();
|
|
107
|
+
const returnValue = [firstCell, lastCell];
|
|
108
|
+
return firstCell.isBefore(lastCell) ? returnValue : returnValue.reverse();
|
|
123
109
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module table/commands/removerowcommand
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from 'ckeditor5/src/core';
|
|
9
|
+
/**
|
|
10
|
+
* The remove row command.
|
|
11
|
+
*
|
|
12
|
+
* The command is registered by {@link module:table/tableediting~TableEditing} as the `'removeTableRow'` editor command.
|
|
13
|
+
*
|
|
14
|
+
* To remove the row containing the selected cell, execute the command:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* editor.execute( 'removeTableRow' );
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export default class RemoveRowCommand extends Command {
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
refresh(): void;
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
execute(): void;
|
|
29
|
+
}
|
|
30
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
31
|
+
interface CommandsMap {
|
|
32
|
+
removeTableRow: RemoveRowCommand;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -2,13 +2,10 @@
|
|
|
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
5
|
/**
|
|
7
6
|
* @module table/commands/removerowcommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Command } from 'ckeditor5/src/core';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* The remove row command.
|
|
14
11
|
*
|
|
@@ -16,84 +13,70 @@ import { Command } from 'ckeditor5/src/core';
|
|
|
16
13
|
*
|
|
17
14
|
* To remove the row containing the selected cell, execute the command:
|
|
18
15
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* editor.execute( 'removeTableRow' );
|
|
18
|
+
* ```
|
|
22
19
|
*/
|
|
23
20
|
export default class RemoveRowCommand extends Command {
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
tableUtils.removeRows( table, {
|
|
67
|
-
at: removedRowIndexes.first,
|
|
68
|
-
rows: rowsToRemove
|
|
69
|
-
} );
|
|
70
|
-
|
|
71
|
-
const cellToFocus = getCellToFocus( table, removedRowIndexes.first, columnIndexToFocus, tableUtils.getRows( table ) );
|
|
72
|
-
|
|
73
|
-
writer.setSelection( writer.createPositionAt( cellToFocus, 0 ) );
|
|
74
|
-
} );
|
|
75
|
-
}
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
refresh() {
|
|
25
|
+
const tableUtils = this.editor.plugins.get('TableUtils');
|
|
26
|
+
const selectedCells = tableUtils.getSelectionAffectedTableCells(this.editor.model.document.selection);
|
|
27
|
+
const firstCell = selectedCells[0];
|
|
28
|
+
if (firstCell) {
|
|
29
|
+
const table = firstCell.findAncestor('table');
|
|
30
|
+
const tableRowCount = tableUtils.getRows(table);
|
|
31
|
+
const lastRowIndex = tableRowCount - 1;
|
|
32
|
+
const selectedRowIndexes = tableUtils.getRowIndexes(selectedCells);
|
|
33
|
+
const areAllRowsSelected = selectedRowIndexes.first === 0 && selectedRowIndexes.last === lastRowIndex;
|
|
34
|
+
// Disallow selecting whole table -> delete whole table should be used instead.
|
|
35
|
+
this.isEnabled = !areAllRowsSelected;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.isEnabled = false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @inheritDoc
|
|
43
|
+
*/
|
|
44
|
+
execute() {
|
|
45
|
+
const model = this.editor.model;
|
|
46
|
+
const tableUtils = this.editor.plugins.get('TableUtils');
|
|
47
|
+
const referenceCells = tableUtils.getSelectionAffectedTableCells(model.document.selection);
|
|
48
|
+
const removedRowIndexes = tableUtils.getRowIndexes(referenceCells);
|
|
49
|
+
const firstCell = referenceCells[0];
|
|
50
|
+
const table = firstCell.findAncestor('table');
|
|
51
|
+
const columnIndexToFocus = tableUtils.getCellLocation(firstCell).column;
|
|
52
|
+
model.change(writer => {
|
|
53
|
+
const rowsToRemove = removedRowIndexes.last - removedRowIndexes.first + 1;
|
|
54
|
+
tableUtils.removeRows(table, {
|
|
55
|
+
at: removedRowIndexes.first,
|
|
56
|
+
rows: rowsToRemove
|
|
57
|
+
});
|
|
58
|
+
const cellToFocus = getCellToFocus(table, removedRowIndexes.first, columnIndexToFocus, tableUtils.getRows(table));
|
|
59
|
+
writer.setSelection(writer.createPositionAt(cellToFocus, 0));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
76
62
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return cellToFocus;
|
|
63
|
+
/**
|
|
64
|
+
* Returns a cell that should be focused before removing the row, belonging to the same column as the currently focused cell.
|
|
65
|
+
* - If the row was not the last one, the cell to focus will be in the row that followed it (before removal).
|
|
66
|
+
* - If the row was the last one, the cell to focus will be in the row that preceded it (before removal).
|
|
67
|
+
*/
|
|
68
|
+
function getCellToFocus(table, removedRowIndex, columnToFocus, tableRowCount) {
|
|
69
|
+
// Don't go beyond last row's index.
|
|
70
|
+
const row = table.getChild(Math.min(removedRowIndex, tableRowCount - 1));
|
|
71
|
+
// Default to first table cell.
|
|
72
|
+
let cellToFocus = row.getChild(0);
|
|
73
|
+
let column = 0;
|
|
74
|
+
for (const tableCell of row.getChildren()) {
|
|
75
|
+
if (column > columnToFocus) {
|
|
76
|
+
return cellToFocus;
|
|
77
|
+
}
|
|
78
|
+
cellToFocus = tableCell;
|
|
79
|
+
column += parseInt(tableCell.getAttribute('colspan') || '1');
|
|
80
|
+
}
|
|
81
|
+
return cellToFocus;
|
|
99
82
|
}
|