@ckeditor/ckeditor5-table 31.1.0 → 34.0.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.
Files changed (146) hide show
  1. package/LICENSE.md +2 -2
  2. package/README.md +2 -1
  3. package/build/table.js +3 -3
  4. package/build/table.js.map +1 -0
  5. package/build/translations/cs.js +1 -1
  6. package/build/translations/el.js +1 -0
  7. package/build/translations/en-au.js +1 -1
  8. package/build/translations/es.js +1 -1
  9. package/build/translations/hr.js +1 -1
  10. package/build/translations/sk.js +1 -1
  11. package/lang/translations/ar.po +1 -1
  12. package/lang/translations/az.po +1 -1
  13. package/lang/translations/bg.po +1 -1
  14. package/lang/translations/cs.po +4 -4
  15. package/lang/translations/da.po +1 -1
  16. package/lang/translations/de-ch.po +1 -1
  17. package/lang/translations/de.po +1 -1
  18. package/lang/translations/el.po +261 -0
  19. package/lang/translations/en-au.po +4 -4
  20. package/lang/translations/en-gb.po +1 -1
  21. package/lang/translations/en.po +1 -1
  22. package/lang/translations/es.po +33 -33
  23. package/lang/translations/et.po +1 -1
  24. package/lang/translations/fa.po +1 -1
  25. package/lang/translations/fi.po +1 -1
  26. package/lang/translations/fr.po +1 -1
  27. package/lang/translations/gl.po +1 -1
  28. package/lang/translations/hi.po +1 -1
  29. package/lang/translations/hr.po +4 -4
  30. package/lang/translations/hu.po +1 -1
  31. package/lang/translations/id.po +1 -1
  32. package/lang/translations/it.po +1 -1
  33. package/lang/translations/ja.po +1 -1
  34. package/lang/translations/ko.po +1 -1
  35. package/lang/translations/ku.po +1 -1
  36. package/lang/translations/lt.po +1 -1
  37. package/lang/translations/lv.po +1 -1
  38. package/lang/translations/nb.po +1 -1
  39. package/lang/translations/ne.po +1 -1
  40. package/lang/translations/nl.po +1 -1
  41. package/lang/translations/no.po +1 -1
  42. package/lang/translations/pl.po +1 -1
  43. package/lang/translations/pt-br.po +1 -1
  44. package/lang/translations/ro.po +1 -1
  45. package/lang/translations/ru.po +1 -1
  46. package/lang/translations/sk.po +4 -4
  47. package/lang/translations/sq.po +1 -1
  48. package/lang/translations/sr-latn.po +1 -1
  49. package/lang/translations/sr.po +1 -1
  50. package/lang/translations/sv.po +1 -1
  51. package/lang/translations/th.po +1 -1
  52. package/lang/translations/tk.po +1 -1
  53. package/lang/translations/tr.po +1 -1
  54. package/lang/translations/ug.po +1 -1
  55. package/lang/translations/uk.po +1 -1
  56. package/lang/translations/uz.po +1 -1
  57. package/lang/translations/vi.po +1 -1
  58. package/lang/translations/zh-cn.po +1 -1
  59. package/lang/translations/zh.po +1 -1
  60. package/package.json +26 -24
  61. package/src/commands/insertcolumncommand.js +5 -5
  62. package/src/commands/insertrowcommand.js +5 -5
  63. package/src/commands/inserttablecommand.js +2 -6
  64. package/src/commands/mergecellcommand.js +5 -6
  65. package/src/commands/mergecellscommand.js +6 -5
  66. package/src/commands/removecolumncommand.js +9 -8
  67. package/src/commands/removerowcommand.js +6 -7
  68. package/src/commands/selectcolumncommand.js +5 -5
  69. package/src/commands/selectrowcommand.js +6 -6
  70. package/src/commands/setheadercolumncommand.js +6 -5
  71. package/src/commands/setheaderrowcommand.js +8 -5
  72. package/src/commands/splitcellcommand.js +5 -5
  73. package/src/converters/downcast.js +77 -408
  74. package/src/converters/table-caption-post-fixer.js +1 -1
  75. package/src/converters/table-cell-paragraph-post-fixer.js +1 -1
  76. package/src/converters/{table-cell-refresh-post-fixer.js → table-cell-refresh-handler.js} +9 -20
  77. package/src/converters/table-headings-refresh-handler.js +68 -0
  78. package/src/converters/table-layout-post-fixer.js +1 -1
  79. package/src/converters/tableproperties.js +1 -1
  80. package/src/converters/upcasttable.js +1 -1
  81. package/src/index.js +2 -1
  82. package/src/plaintableoutput.js +151 -0
  83. package/src/table.js +1 -1
  84. package/src/tablecaption/tablecaptionediting.js +1 -1
  85. package/src/tablecaption/tablecaptionui.js +3 -3
  86. package/src/tablecaption/toggletablecaptioncommand.js +3 -3
  87. package/src/tablecaption/utils.js +1 -1
  88. package/src/tablecaption.js +1 -1
  89. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +1 -1
  90. package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +1 -1
  91. package/src/tablecellproperties/commands/tablecellborderstylecommand.js +1 -1
  92. package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +1 -1
  93. package/src/tablecellproperties/commands/tablecellheightcommand.js +1 -1
  94. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +1 -1
  95. package/src/tablecellproperties/commands/tablecellpaddingcommand.js +1 -1
  96. package/src/tablecellproperties/commands/tablecellpropertycommand.js +6 -5
  97. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +1 -1
  98. package/src/tablecellproperties/commands/tablecellwidthcommand.js +1 -1
  99. package/src/tablecellproperties/tablecellpropertiesediting.js +1 -1
  100. package/src/tablecellproperties/tablecellpropertiesui.js +1 -1
  101. package/src/tablecellproperties/ui/tablecellpropertiesview.js +1 -1
  102. package/src/tablecellproperties.js +1 -1
  103. package/src/tableclipboard.js +19 -16
  104. package/src/tableediting.js +52 -33
  105. package/src/tablekeyboard.js +74 -71
  106. package/src/tablemouse/mouseeventsobserver.js +1 -1
  107. package/src/tablemouse.js +7 -5
  108. package/src/tableproperties/commands/tablealignmentcommand.js +1 -1
  109. package/src/tableproperties/commands/tablebackgroundcolorcommand.js +1 -1
  110. package/src/tableproperties/commands/tablebordercolorcommand.js +1 -1
  111. package/src/tableproperties/commands/tableborderstylecommand.js +1 -1
  112. package/src/tableproperties/commands/tableborderwidthcommand.js +1 -1
  113. package/src/tableproperties/commands/tableheightcommand.js +1 -1
  114. package/src/tableproperties/commands/tablepropertycommand.js +2 -2
  115. package/src/tableproperties/commands/tablewidthcommand.js +1 -1
  116. package/src/tableproperties/tablepropertiesediting.js +1 -1
  117. package/src/tableproperties/tablepropertiesui.js +1 -1
  118. package/src/tableproperties/ui/tablepropertiesview.js +1 -1
  119. package/src/tableproperties.js +1 -1
  120. package/src/tableselection.js +10 -9
  121. package/src/tabletoolbar.js +1 -1
  122. package/src/tableui.js +1 -1
  123. package/src/tableutils.js +311 -1
  124. package/src/tablewalker.js +1 -1
  125. package/src/ui/colorinputview.js +1 -1
  126. package/src/ui/formrowview.js +1 -1
  127. package/src/ui/inserttableview.js +1 -1
  128. package/src/utils/common.js +1 -1
  129. package/src/utils/structure.js +1 -1
  130. package/src/utils/table-properties.js +1 -1
  131. package/src/utils/ui/contextualballoon.js +1 -1
  132. package/src/utils/ui/table-properties.js +1 -1
  133. package/src/utils/ui/widget.js +1 -1
  134. package/theme/colorinput.css +1 -1
  135. package/theme/form.css +1 -1
  136. package/theme/formrow.css +1 -1
  137. package/theme/inserttable.css +1 -1
  138. package/theme/table.css +2 -2
  139. package/theme/tablecaption.css +1 -1
  140. package/theme/tablecellproperties.css +1 -1
  141. package/theme/tableediting.css +1 -1
  142. package/theme/tableform.css +1 -1
  143. package/theme/tableproperties.css +1 -1
  144. package/theme/tableselection.css +1 -1
  145. package/src/converters/table-heading-rows-refresh-post-fixer.js +0 -72
  146. package/src/utils/selection.js +0 -276
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -10,14 +10,7 @@
10
10
  import { Plugin } from 'ckeditor5/src/core';
11
11
 
12
12
  import upcastTable, { ensureParagraphInTableCell, skipEmptyTableRow, upcastTableFigure } from './converters/upcasttable';
13
- import {
14
- convertParagraphInTableCell,
15
- downcastInsertCell,
16
- downcastInsertRow,
17
- downcastInsertTable,
18
- downcastRemoveRow,
19
- downcastTableHeadingColumnsChange
20
- } from './converters/downcast';
13
+ import { convertParagraphInTableCell, downcastCell, downcastRow, downcastTable } from './converters/downcast';
21
14
 
22
15
  import InsertTableCommand from './commands/inserttablecommand';
23
16
  import InsertRowCommand from './commands/insertrowcommand';
@@ -35,8 +28,9 @@ import TableUtils from '../src/tableutils';
35
28
 
36
29
  import injectTableLayoutPostFixer from './converters/table-layout-post-fixer';
37
30
  import injectTableCellParagraphPostFixer from './converters/table-cell-paragraph-post-fixer';
38
- import injectTableCellRefreshPostFixer from './converters/table-cell-refresh-post-fixer';
39
- import injectTableHeadingRowsRefreshPostFixer from './converters/table-heading-rows-refresh-post-fixer';
31
+
32
+ import tableHeadingsRefreshHandler from './converters/table-headings-refresh-handler';
33
+ import tableCellRefreshHandler from './converters/table-cell-refresh-handler';
40
34
 
41
35
  import '../theme/tableediting.css';
42
36
 
@@ -53,6 +47,13 @@ export default class TableEditing extends Plugin {
53
47
  return 'TableEditing';
54
48
  }
55
49
 
50
+ /**
51
+ * @inheritDoc
52
+ */
53
+ static get requires() {
54
+ return [ TableUtils ];
55
+ }
56
+
56
57
  /**
57
58
  * @inheritDoc
58
59
  */
@@ -61,12 +62,11 @@ export default class TableEditing extends Plugin {
61
62
  const model = editor.model;
62
63
  const schema = model.schema;
63
64
  const conversion = editor.conversion;
65
+ const tableUtils = editor.plugins.get( TableUtils );
64
66
 
65
67
  schema.register( 'table', {
66
- allowWhere: '$block',
67
- allowAttributes: [ 'headingRows', 'headingColumns' ],
68
- isObject: true,
69
- isBlock: true
68
+ inheritAllFrom: '$blockObject',
69
+ allowAttributes: [ 'headingRows', 'headingColumns' ]
70
70
  } );
71
71
 
72
72
  schema.register( 'tableRow', {
@@ -75,8 +75,8 @@ export default class TableEditing extends Plugin {
75
75
  } );
76
76
 
77
77
  schema.register( 'tableCell', {
78
+ allowContentOf: '$container',
78
79
  allowIn: 'tableRow',
79
- allowChildren: '$block',
80
80
  allowAttributes: [ 'colspan', 'rowspan' ],
81
81
  isLimit: true,
82
82
  isSelectable: true
@@ -88,15 +88,29 @@ export default class TableEditing extends Plugin {
88
88
  // Table conversion.
89
89
  conversion.for( 'upcast' ).add( upcastTable() );
90
90
 
91
- conversion.for( 'editingDowncast' ).add( downcastInsertTable( { asWidget: true } ) );
92
- conversion.for( 'dataDowncast' ).add( downcastInsertTable() );
91
+ conversion.for( 'editingDowncast' ).elementToStructure( {
92
+ model: {
93
+ name: 'table',
94
+ attributes: [ 'headingRows' ]
95
+ },
96
+ view: downcastTable( tableUtils, { asWidget: true } )
97
+ } );
98
+ conversion.for( 'dataDowncast' ).elementToStructure( {
99
+ model: {
100
+ name: 'table',
101
+ attributes: [ 'headingRows' ]
102
+ },
103
+ view: downcastTable( tableUtils )
104
+ } );
93
105
 
94
106
  // Table row conversion.
95
107
  conversion.for( 'upcast' ).elementToElement( { model: 'tableRow', view: 'tr' } );
96
108
  conversion.for( 'upcast' ).add( skipEmptyTableRow() );
97
109
 
98
- conversion.for( 'editingDowncast' ).add( downcastInsertRow() );
99
- conversion.for( 'editingDowncast' ).add( downcastRemoveRow() );
110
+ conversion.for( 'downcast' ).elementToElement( {
111
+ model: 'tableRow',
112
+ view: downcastRow()
113
+ } );
100
114
 
101
115
  // Table cell conversion.
102
116
  conversion.for( 'upcast' ).elementToElement( { model: 'tableCell', view: 'td' } );
@@ -104,12 +118,24 @@ export default class TableEditing extends Plugin {
104
118
  conversion.for( 'upcast' ).add( ensureParagraphInTableCell( 'td' ) );
105
119
  conversion.for( 'upcast' ).add( ensureParagraphInTableCell( 'th' ) );
106
120
 
107
- conversion.for( 'editingDowncast' ).add( downcastInsertCell() );
121
+ conversion.for( 'editingDowncast' ).elementToElement( {
122
+ model: 'tableCell',
123
+ view: downcastCell( { asWidget: true } )
124
+ } );
125
+ conversion.for( 'dataDowncast' ).elementToElement( {
126
+ model: 'tableCell',
127
+ view: downcastCell()
128
+ } );
108
129
 
109
130
  // Duplicates code - needed to properly refresh paragraph inside a table cell.
110
131
  conversion.for( 'editingDowncast' ).elementToElement( {
111
132
  model: 'paragraph',
112
- view: convertParagraphInTableCell,
133
+ view: convertParagraphInTableCell( { asWidget: true } ),
134
+ converterPriority: 'high'
135
+ } );
136
+ conversion.for( 'dataDowncast' ).elementToElement( {
137
+ model: 'paragraph',
138
+ view: convertParagraphInTableCell(),
113
139
  converterPriority: 'high'
114
140
  } );
115
141
 
@@ -126,9 +152,6 @@ export default class TableEditing extends Plugin {
126
152
  view: 'rowspan'
127
153
  } );
128
154
 
129
- // Table heading columns conversion (a change of heading rows requires a reconversion of the whole table).
130
- conversion.for( 'editingDowncast' ).add( downcastTableHeadingColumnsChange() );
131
-
132
155
  // Manually adjust model position mappings in a special case, when a table cell contains a paragraph, which is bound
133
156
  // to its parent (to the table cell). This custom model-to-view position mapping is necessary in data pipeline only,
134
157
  // because only during this conversion a paragraph can be bound to its parent.
@@ -164,17 +187,13 @@ export default class TableEditing extends Plugin {
164
187
  editor.commands.add( 'selectTableRow', new SelectRowCommand( editor ) );
165
188
  editor.commands.add( 'selectTableColumn', new SelectColumnCommand( editor ) );
166
189
 
167
- injectTableHeadingRowsRefreshPostFixer( model );
168
190
  injectTableLayoutPostFixer( model );
169
- injectTableCellRefreshPostFixer( model, editor.editing.mapper );
170
191
  injectTableCellParagraphPostFixer( model );
171
- }
172
192
 
173
- /**
174
- * @inheritDoc
175
- */
176
- static get requires() {
177
- return [ TableUtils ];
193
+ this.listenTo( model.document, 'change:data', () => {
194
+ tableHeadingsRefreshHandler( model, editor.editing );
195
+ tableCellRefreshHandler( model, editor.editing );
196
+ } );
178
197
  }
179
198
  }
180
199
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -9,10 +9,10 @@
9
9
 
10
10
  import TableSelection from './tableselection';
11
11
  import TableWalker from './tablewalker';
12
+ import TableUtils from './tableutils';
12
13
 
13
14
  import { Plugin } from 'ckeditor5/src/core';
14
15
  import { getLocalizedArrowKeyCodeDirection } from 'ckeditor5/src/utils';
15
- import { getSelectedTableCells, getTableCellsContainingSelection } from './utils/selection';
16
16
 
17
17
  /**
18
18
  * This plugin enables keyboard navigation for tables.
@@ -32,7 +32,7 @@ export default class TableKeyboard extends Plugin {
32
32
  * @inheritDoc
33
33
  */
34
34
  static get requires() {
35
- return [ TableSelection ];
35
+ return [ TableSelection, TableUtils ];
36
36
  }
37
37
 
38
38
  /**
@@ -42,23 +42,20 @@ export default class TableKeyboard extends Plugin {
42
42
  const view = this.editor.editing.view;
43
43
  const viewDocument = view.document;
44
44
 
45
- // Handle Tab key navigation.
46
- this.editor.keystrokes.set( 'Tab', ( ...args ) => this._handleTabOnSelectedTable( ...args ), { priority: 'low' } );
47
- this.editor.keystrokes.set( 'Tab', this._getTabHandler( true ), { priority: 'low' } );
48
- this.editor.keystrokes.set( 'Shift+Tab', this._getTabHandler( false ), { priority: 'low' } );
49
-
50
45
  this.listenTo( viewDocument, 'arrowKey', ( ...args ) => this._onArrowKey( ...args ), { context: 'table' } );
46
+ this.listenTo( viewDocument, 'tab', ( ...args ) => this._handleTabOnSelectedTable( ...args ), { context: 'figure' } );
47
+ this.listenTo( viewDocument, 'tab', ( ...args ) => this._handleTab( ...args ), { context: [ 'th', 'td' ] } );
51
48
  }
52
49
 
53
50
  /**
54
- * Handles {@link module:engine/view/document~Document#event:keydown keydown} events for the <kbd>Tab</kbd> key executed
51
+ * Handles {@link module:engine/view/document~Document#event:tab tab} events for the <kbd>Tab</kbd> key executed
55
52
  * when the table widget is selected.
56
53
  *
57
54
  * @private
58
- * @param {module:engine/view/observer/keyobserver~KeyEventData} data Key event data.
59
- * @param {Function} cancel The stop/stopPropagation/preventDefault function.
55
+ * @param {module:engine/view/observer/bubblingeventinfo~BubblingEventInfo} bubblingEventInfo
56
+ * @param {module:engine/view/observer/domeventdata~DomEventData} domEventData
60
57
  */
61
- _handleTabOnSelectedTable( data, cancel ) {
58
+ _handleTabOnSelectedTable( bubblingEventInfo, domEventData ) {
62
59
  const editor = this.editor;
63
60
  const selection = editor.model.document.selection;
64
61
  const selectedElement = selection.getSelectedElement();
@@ -67,7 +64,9 @@ export default class TableKeyboard extends Plugin {
67
64
  return;
68
65
  }
69
66
 
70
- cancel();
67
+ domEventData.preventDefault();
68
+ domEventData.stopPropagation();
69
+ bubblingEventInfo.stop();
71
70
 
72
71
  editor.model.change( writer => {
73
72
  writer.setSelection( writer.createRangeIn( selectedElement.getChild( 0 ).getChild( 0 ) ) );
@@ -75,87 +74,90 @@ export default class TableKeyboard extends Plugin {
75
74
  }
76
75
 
77
76
  /**
78
- * Returns a handler for {@link module:engine/view/document~Document#event:keydown keydown} events for the <kbd>Tab</kbd> key executed
77
+ * Handles {@link module:engine/view/document~Document#event:tab tab} events for the <kbd>Tab</kbd> key executed
79
78
  * inside table cells.
80
79
  *
81
80
  * @private
82
- * @param {Boolean} isForward Whether this handler will move the selection to the next or the previous cell.
81
+ * @param {module:engine/view/observer/bubblingeventinfo~BubblingEventInfo} bubblingEventInfo
82
+ * @param {module:engine/view/observer/domeventdata~DomEventData} domEventData
83
83
  */
84
- _getTabHandler( isForward ) {
84
+ _handleTab( bubblingEventInfo, domEventData ) {
85
85
  const editor = this.editor;
86
+ const tableUtils = this.editor.plugins.get( TableUtils );
86
87
 
87
- return ( domEventData, cancel ) => {
88
- const selection = editor.model.document.selection;
89
- let tableCell = getTableCellsContainingSelection( selection )[ 0 ];
88
+ const selection = editor.model.document.selection;
89
+ const isForward = !domEventData.shiftKey;
90
90
 
91
- if ( !tableCell ) {
92
- tableCell = this.editor.plugins.get( 'TableSelection' ).getFocusCell();
93
- }
91
+ let tableCell = tableUtils.getTableCellsContainingSelection( selection )[ 0 ];
94
92
 
95
- if ( !tableCell ) {
96
- return;
97
- }
93
+ if ( !tableCell ) {
94
+ tableCell = this.editor.plugins.get( 'TableSelection' ).getFocusCell();
95
+ }
98
96
 
99
- cancel();
97
+ if ( !tableCell ) {
98
+ return;
99
+ }
100
100
 
101
- const tableRow = tableCell.parent;
102
- const table = tableRow.parent;
101
+ domEventData.preventDefault();
102
+ domEventData.stopPropagation();
103
+ bubblingEventInfo.stop();
103
104
 
104
- const currentRowIndex = table.getChildIndex( tableRow );
105
- const currentCellIndex = tableRow.getChildIndex( tableCell );
105
+ const tableRow = tableCell.parent;
106
+ const table = tableRow.parent;
106
107
 
107
- const isFirstCellInRow = currentCellIndex === 0;
108
+ const currentRowIndex = table.getChildIndex( tableRow );
109
+ const currentCellIndex = tableRow.getChildIndex( tableCell );
108
110
 
109
- if ( !isForward && isFirstCellInRow && currentRowIndex === 0 ) {
110
- // Set the selection over the whole table if the selection was in the first table cell.
111
- editor.model.change( writer => {
112
- writer.setSelection( writer.createRangeOn( table ) );
113
- } );
111
+ const isFirstCellInRow = currentCellIndex === 0;
114
112
 
115
- return;
116
- }
113
+ if ( !isForward && isFirstCellInRow && currentRowIndex === 0 ) {
114
+ // Set the selection over the whole table if the selection was in the first table cell.
115
+ editor.model.change( writer => {
116
+ writer.setSelection( writer.createRangeOn( table ) );
117
+ } );
117
118
 
118
- const tableUtils = this.editor.plugins.get( 'TableUtils' );
119
- const isLastCellInRow = currentCellIndex === tableRow.childCount - 1;
120
- const isLastRow = currentRowIndex === tableUtils.getRows( table ) - 1;
119
+ return;
120
+ }
121
121
 
122
- if ( isForward && isLastRow && isLastCellInRow ) {
123
- editor.execute( 'insertTableRowBelow' );
122
+ const isLastCellInRow = currentCellIndex === tableRow.childCount - 1;
123
+ const isLastRow = currentRowIndex === tableUtils.getRows( table ) - 1;
124
124
 
125
- // Check if the command actually added a row. If `insertTableRowBelow` execution didn't add a row (because it was disabled
126
- // or it got overwritten) set the selection over the whole table to mirror the first cell case.
127
- if ( currentRowIndex === tableUtils.getRows( table ) - 1 ) {
128
- editor.model.change( writer => {
129
- writer.setSelection( writer.createRangeOn( table ) );
130
- } );
125
+ if ( isForward && isLastRow && isLastCellInRow ) {
126
+ editor.execute( 'insertTableRowBelow' );
131
127
 
132
- return;
133
- }
128
+ // Check if the command actually added a row. If `insertTableRowBelow` execution didn't add a row (because it was disabled
129
+ // or it got overwritten) set the selection over the whole table to mirror the first cell case.
130
+ if ( currentRowIndex === tableUtils.getRows( table ) - 1 ) {
131
+ editor.model.change( writer => {
132
+ writer.setSelection( writer.createRangeOn( table ) );
133
+ } );
134
+
135
+ return;
134
136
  }
137
+ }
135
138
 
136
- let cellToFocus;
139
+ let cellToFocus;
137
140
 
138
- // Move to the first cell in the next row.
139
- if ( isForward && isLastCellInRow ) {
140
- const nextRow = table.getChild( currentRowIndex + 1 );
141
+ // Move to the first cell in the next row.
142
+ if ( isForward && isLastCellInRow ) {
143
+ const nextRow = table.getChild( currentRowIndex + 1 );
141
144
 
142
- cellToFocus = nextRow.getChild( 0 );
143
- }
144
- // Move to the last cell in the previous row.
145
- else if ( !isForward && isFirstCellInRow ) {
146
- const previousRow = table.getChild( currentRowIndex - 1 );
145
+ cellToFocus = nextRow.getChild( 0 );
146
+ }
147
+ // Move to the last cell in the previous row.
148
+ else if ( !isForward && isFirstCellInRow ) {
149
+ const previousRow = table.getChild( currentRowIndex - 1 );
147
150
 
148
- cellToFocus = previousRow.getChild( previousRow.childCount - 1 );
149
- }
150
- // Move to the next/previous cell.
151
- else {
152
- cellToFocus = tableRow.getChild( currentCellIndex + ( isForward ? 1 : -1 ) );
153
- }
151
+ cellToFocus = previousRow.getChild( previousRow.childCount - 1 );
152
+ }
153
+ // Move to the next/previous cell.
154
+ else {
155
+ cellToFocus = tableRow.getChild( currentCellIndex + ( isForward ? 1 : -1 ) );
156
+ }
154
157
 
155
- editor.model.change( writer => {
156
- writer.setSelection( writer.createRangeIn( cellToFocus ) );
157
- } );
158
- };
158
+ editor.model.change( writer => {
159
+ writer.setSelection( writer.createRangeIn( cellToFocus ) );
160
+ } );
159
161
  }
160
162
 
161
163
  /**
@@ -188,13 +190,14 @@ export default class TableKeyboard extends Plugin {
188
190
  * @returns {Boolean} Returns `true` if key was handled.
189
191
  */
190
192
  _handleArrowKeys( direction, expandSelection ) {
193
+ const tableUtils = this.editor.plugins.get( TableUtils );
191
194
  const model = this.editor.model;
192
195
  const selection = model.document.selection;
193
196
  const isForward = [ 'right', 'down' ].includes( direction );
194
197
 
195
198
  // In case one or more table cells are selected (from outside),
196
199
  // move the selection to a cell adjacent to the selected table fragment.
197
- const selectedCells = getSelectedTableCells( selection );
200
+ const selectedCells = tableUtils.getSelectedTableCells( selection );
198
201
 
199
202
  if ( selectedCells.length ) {
200
203
  let focusCell;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
package/src/tablemouse.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -11,8 +11,7 @@ import { Plugin } from 'ckeditor5/src/core';
11
11
 
12
12
  import TableSelection from './tableselection';
13
13
  import MouseEventsObserver from './tablemouse/mouseeventsobserver';
14
-
15
- import { getTableCellsContainingSelection } from './utils/selection';
14
+ import TableUtils from './tableutils';
16
15
 
17
16
  /**
18
17
  * This plugin enables a table cells' selection with the mouse.
@@ -32,7 +31,7 @@ export default class TableMouse extends Plugin {
32
31
  * @inheritDoc
33
32
  */
34
33
  static get requires() {
35
- return [ TableSelection ];
34
+ return [ TableSelection, TableUtils ];
36
35
  }
37
36
 
38
37
  /**
@@ -57,11 +56,14 @@ export default class TableMouse extends Plugin {
57
56
  */
58
57
  _enableShiftClickSelection() {
59
58
  const editor = this.editor;
59
+ const tableUtils = editor.plugins.get( TableUtils );
60
60
  let blockSelectionChange = false;
61
61
 
62
62
  const tableSelection = editor.plugins.get( TableSelection );
63
63
 
64
64
  this.listenTo( editor.editing.view.document, 'mousedown', ( evt, domEventData ) => {
65
+ const selection = editor.model.document.selection;
66
+
65
67
  if ( !this.isEnabled || !tableSelection.isEnabled ) {
66
68
  return;
67
69
  }
@@ -70,7 +72,7 @@ export default class TableMouse extends Plugin {
70
72
  return;
71
73
  }
72
74
 
73
- const anchorCell = tableSelection.getAnchorCell() || getTableCellsContainingSelection( editor.model.document.selection )[ 0 ];
75
+ const anchorCell = tableSelection.getAnchorCell() || tableUtils.getTableCellsContainingSelection( selection )[ 0 ];
74
76
 
75
77
  if ( !anchorCell ) {
76
78
  return;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -77,7 +77,7 @@ export default class TablePropertyCommand extends Command {
77
77
  const table = selection.getFirstPosition().findAncestor( 'table' );
78
78
  const valueToSet = this._getValueToSet( value );
79
79
 
80
- model.enqueueChange( batch || 'default', writer => {
80
+ model.enqueueChange( batch, writer => {
81
81
  if ( valueToSet ) {
82
82
  writer.setAttribute( this.attributeName, valueToSet, table );
83
83
  } else {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
@@ -14,7 +14,6 @@ import TableWalker from './tablewalker';
14
14
  import TableUtils from './tableutils';
15
15
 
16
16
  import { cropTableToDimensions, adjustLastRowIndex, adjustLastColumnIndex } from './utils/structure';
17
- import { getColumnIndexes, getRowIndexes, getSelectedTableCells, isSelectionRectangular } from './utils/selection';
18
17
 
19
18
  import '../theme/tableselection.css';
20
19
 
@@ -36,7 +35,7 @@ export default class TableSelection extends Plugin {
36
35
  * @inheritDoc
37
36
  */
38
37
  static get requires() {
39
- return [ TableUtils ];
38
+ return [ TableUtils, TableUtils ];
40
39
  }
41
40
 
42
41
  /**
@@ -58,9 +57,10 @@ export default class TableSelection extends Plugin {
58
57
  * @returns {Array.<module:engine/model/element~Element>|null}
59
58
  */
60
59
  getSelectedTableCells() {
60
+ const tableUtils = this.editor.plugins.get( TableUtils );
61
61
  const selection = this.editor.model.document.selection;
62
62
 
63
- const selectedCells = getSelectedTableCells( selection );
63
+ const selectedCells = tableUtils.getSelectedTableCells( selection );
64
64
 
65
65
  if ( selectedCells.length == 0 ) {
66
66
  return null;
@@ -81,6 +81,7 @@ export default class TableSelection extends Plugin {
81
81
  * @returns {module:engine/model/documentfragment~DocumentFragment|null}
82
82
  */
83
83
  getSelectionAsFragment() {
84
+ const tableUtils = this.editor.plugins.get( TableUtils );
84
85
  const selectedCells = this.getSelectedTableCells();
85
86
 
86
87
  if ( !selectedCells ) {
@@ -89,10 +90,9 @@ export default class TableSelection extends Plugin {
89
90
 
90
91
  return this.editor.model.change( writer => {
91
92
  const documentFragment = writer.createDocumentFragment();
92
- const tableUtils = this.editor.plugins.get( 'TableUtils' );
93
93
 
94
- const { first: firstColumn, last: lastColumn } = getColumnIndexes( selectedCells );
95
- const { first: firstRow, last: lastRow } = getRowIndexes( selectedCells );
94
+ const { first: firstColumn, last: lastColumn } = tableUtils.getColumnIndexes( selectedCells );
95
+ const { first: firstRow, last: lastRow } = tableUtils.getRowIndexes( selectedCells );
96
96
 
97
97
  const sourceTable = selectedCells[ 0 ].findAncestor( 'table' );
98
98
 
@@ -101,7 +101,7 @@ export default class TableSelection extends Plugin {
101
101
 
102
102
  // If the selection is rectangular there could be a case of all cells in the last row/column spanned over
103
103
  // next row/column so the real lastRow/lastColumn should be updated.
104
- if ( isSelectionRectangular( selectedCells, tableUtils ) ) {
104
+ if ( tableUtils.isSelectionRectangular( selectedCells ) ) {
105
105
  const dimensions = {
106
106
  firstColumn,
107
107
  lastColumn,
@@ -269,10 +269,11 @@ export default class TableSelection extends Plugin {
269
269
  * @param {Array.<*>} args Delete content method arguments.
270
270
  */
271
271
  _handleDeleteContent( event, args ) {
272
+ const tableUtils = this.editor.plugins.get( TableUtils );
272
273
  const [ selection, options ] = args;
273
274
  const model = this.editor.model;
274
275
  const isBackward = !options || options.direction == 'backward';
275
- const selectedTableCells = getSelectedTableCells( selection );
276
+ const selectedTableCells = tableUtils.getSelectedTableCells( selection );
276
277
 
277
278
  if ( !selectedTableCells.length ) {
278
279
  return;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5
 
package/src/tableui.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, 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
5