@ckeditor/ckeditor5-table 31.0.0 → 33.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/build/table.js +3 -3
  3. package/build/table.js.map +1 -0
  4. package/build/translations/cs.js +1 -1
  5. package/build/translations/el.js +1 -0
  6. package/build/translations/es.js +1 -1
  7. package/build/translations/id.js +1 -1
  8. package/build/translations/pt-br.js +1 -1
  9. package/build/translations/uz.js +1 -0
  10. package/build/translations/zh.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 +1 -1
  20. package/lang/translations/en-gb.po +1 -1
  21. package/lang/translations/en.po +1 -1
  22. package/lang/translations/es.po +43 -43
  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 +1 -1
  30. package/lang/translations/hu.po +1 -1
  31. package/lang/translations/id.po +11 -11
  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 +4 -4
  44. package/lang/translations/ro.po +1 -1
  45. package/lang/translations/ru.po +1 -1
  46. package/lang/translations/sk.po +1 -1
  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 +261 -0
  57. package/lang/translations/vi.po +1 -1
  58. package/lang/translations/zh-cn.po +1 -1
  59. package/lang/translations/zh.po +4 -4
  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 +1 -1
  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 +6 -5
  80. package/src/converters/upcasttable.js +7 -3
  81. package/src/index.js +1 -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 +2 -2
  90. package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +2 -2
  91. package/src/tablecellproperties/commands/tablecellborderstylecommand.js +2 -2
  92. package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +2 -2
  93. package/src/tablecellproperties/commands/tablecellheightcommand.js +2 -2
  94. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +2 -2
  95. package/src/tablecellproperties/commands/tablecellpaddingcommand.js +2 -2
  96. package/src/tablecellproperties/commands/tablecellpropertycommand.js +6 -5
  97. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +2 -2
  98. package/src/tablecellproperties/commands/tablecellwidthcommand.js +2 -2
  99. package/src/tablecellproperties/tablecellpropertiesediting.js +42 -35
  100. package/src/tablecellproperties/tablecellpropertiesui.js +1 -1
  101. package/src/tablecellproperties/ui/tablecellpropertiesview.js +11 -1
  102. package/src/tablecellproperties.js +1 -1
  103. package/src/tableclipboard.js +19 -16
  104. package/src/tableediting.js +49 -28
  105. package/src/tablekeyboard.js +7 -6
  106. package/src/tablemouse/mouseeventsobserver.js +1 -1
  107. package/src/tablemouse.js +7 -5
  108. package/src/tableproperties/commands/tablealignmentcommand.js +2 -2
  109. package/src/tableproperties/commands/tablebackgroundcolorcommand.js +2 -2
  110. package/src/tableproperties/commands/tablebordercolorcommand.js +2 -2
  111. package/src/tableproperties/commands/tableborderstylecommand.js +2 -2
  112. package/src/tableproperties/commands/tableborderwidthcommand.js +2 -2
  113. package/src/tableproperties/commands/tableheightcommand.js +2 -2
  114. package/src/tableproperties/commands/tablepropertycommand.js +2 -2
  115. package/src/tableproperties/commands/tablewidthcommand.js +2 -2
  116. package/src/tableproperties/tablepropertiesediting.js +29 -21
  117. package/src/tableproperties/tablepropertiesui.js +1 -1
  118. package/src/tableproperties/ui/tablepropertiesview.js +11 -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
 
@@ -31,11 +31,11 @@ const ALIGN_VALUES_REG_EXP = /^(left|center|right|justify)$/;
31
31
  *
32
32
  * Introduces table cell model attributes and their conversion:
33
33
  *
34
- * - border: `borderStyle`, `borderColor` and `borderWidth`
35
- * - background color: `backgroundColor`
36
- * - cell padding: `padding`
37
- * - horizontal and vertical alignment: `horizontalAlignment`, `verticalAlignment`
38
- * - cell width and height: `width`, `height`
34
+ * - border: `tableCellBorderStyle`, `tableCellBorderColor` and `tableCellBorderWidth`
35
+ * - background color: `tableCellBackgroundColor`
36
+ * - cell padding: `tableCellPadding`
37
+ * - horizontal and vertical alignment: `tableCellHorizontalAlignment`, `tableCellVerticalAlignment`
38
+ * - cell width and height: `tableCellWidth`, `tableCellHeight`
39
39
  *
40
40
  * It also registers commands used to manipulate the above attributes:
41
41
  *
@@ -92,21 +92,15 @@ export default class TableCellPropertiesEditing extends Plugin {
92
92
  editor.commands.add( 'tableCellBorderColor', new TableCellBorderColorCommand( editor, defaultTableCellProperties.borderColor ) );
93
93
  editor.commands.add( 'tableCellBorderWidth', new TableCellBorderWidthCommand( editor, defaultTableCellProperties.borderWidth ) );
94
94
 
95
- enableHorizontalAlignmentProperty( schema, conversion, defaultTableCellProperties.horizontalAlignment );
96
- editor.commands.add(
97
- 'tableCellHorizontalAlignment',
98
- new TableCellHorizontalAlignmentCommand( editor, defaultTableCellProperties.horizontalAlignment )
99
- );
100
-
101
95
  enableProperty( schema, conversion, {
102
- modelAttribute: 'width',
96
+ modelAttribute: 'tableCellWidth',
103
97
  styleName: 'width',
104
98
  defaultValue: defaultTableCellProperties.width
105
99
  } );
106
100
  editor.commands.add( 'tableCellWidth', new TableCellWidthCommand( editor, defaultTableCellProperties.width ) );
107
101
 
108
102
  enableProperty( schema, conversion, {
109
- modelAttribute: 'height',
103
+ modelAttribute: 'tableCellHeight',
110
104
  styleName: 'height',
111
105
  defaultValue: defaultTableCellProperties.height
112
106
  } );
@@ -114,7 +108,7 @@ export default class TableCellPropertiesEditing extends Plugin {
114
108
 
115
109
  editor.data.addStyleProcessorRules( addPaddingRules );
116
110
  enableProperty( schema, conversion, {
117
- modelAttribute: 'padding',
111
+ modelAttribute: 'tableCellPadding',
118
112
  styleName: 'padding',
119
113
  reduceBoxSides: true,
120
114
  defaultValue: defaultTableCellProperties.padding
@@ -123,7 +117,7 @@ export default class TableCellPropertiesEditing extends Plugin {
123
117
 
124
118
  editor.data.addStyleProcessorRules( addBackgroundRules );
125
119
  enableProperty( schema, conversion, {
126
- modelAttribute: 'backgroundColor',
120
+ modelAttribute: 'tableCellBackgroundColor',
127
121
  styleName: 'background-color',
128
122
  defaultValue: defaultTableCellProperties.backgroundColor
129
123
  } );
@@ -132,6 +126,12 @@ export default class TableCellPropertiesEditing extends Plugin {
132
126
  new TableCellBackgroundColorCommand( editor, defaultTableCellProperties.backgroundColor )
133
127
  );
134
128
 
129
+ enableHorizontalAlignmentProperty( schema, conversion, defaultTableCellProperties.horizontalAlignment );
130
+ editor.commands.add(
131
+ 'tableCellHorizontalAlignment',
132
+ new TableCellHorizontalAlignmentCommand( editor, defaultTableCellProperties.horizontalAlignment )
133
+ );
134
+
135
135
  enableVerticalAlignmentProperty( schema, conversion, defaultTableCellProperties.verticalAlignment );
136
136
  editor.commands.add(
137
137
  'tableCellVerticalAlignment',
@@ -140,26 +140,33 @@ export default class TableCellPropertiesEditing extends Plugin {
140
140
  }
141
141
  }
142
142
 
143
- // Enables the `'borderStyle'`, `'borderColor'` and `'borderWidth'` attributes for table cells.
143
+ // Enables the `'tableCellBorderStyle'`, `'tableCellBorderColor'` and `'tableCellBorderWidth'` attributes for table cells.
144
144
  //
145
145
  // @param {module:engine/model/schema~Schema} schema
146
146
  // @param {module:engine/conversion/conversion~Conversion} conversion
147
147
  // @param {Object} defaultBorder The default border values.
148
- // @param {String} defaultBorder.color The default `borderColor` value.
149
- // @param {String} defaultBorder.style The default `borderStyle` value.
150
- // @param {String} defaultBorder.width The default `borderWidth` value.
148
+ // @param {String} defaultBorder.color The default `tableCellBorderColor` value.
149
+ // @param {String} defaultBorder.style The default `tableCellBorderStyle` value.
150
+ // @param {String} defaultBorder.width The default `tableCellBorderWidth` value.
151
151
  function enableBorderProperties( schema, conversion, defaultBorder ) {
152
+ const modelAttributes = {
153
+ width: 'tableCellBorderWidth',
154
+ color: 'tableCellBorderColor',
155
+ style: 'tableCellBorderStyle'
156
+ };
157
+
152
158
  schema.extend( 'tableCell', {
153
- allowAttributes: [ 'borderWidth', 'borderColor', 'borderStyle' ]
159
+ allowAttributes: Object.values( modelAttributes )
154
160
  } );
155
- upcastBorderStyles( conversion, 'td', defaultBorder );
156
- upcastBorderStyles( conversion, 'th', defaultBorder );
157
- downcastAttributeToStyle( conversion, { modelElement: 'tableCell', modelAttribute: 'borderStyle', styleName: 'border-style' } );
158
- downcastAttributeToStyle( conversion, { modelElement: 'tableCell', modelAttribute: 'borderColor', styleName: 'border-color' } );
159
- downcastAttributeToStyle( conversion, { modelElement: 'tableCell', modelAttribute: 'borderWidth', styleName: 'border-width' } );
161
+
162
+ upcastBorderStyles( conversion, 'td', modelAttributes, defaultBorder );
163
+ upcastBorderStyles( conversion, 'th', modelAttributes, defaultBorder );
164
+ downcastAttributeToStyle( conversion, { modelElement: 'tableCell', modelAttribute: modelAttributes.style, styleName: 'border-style' } );
165
+ downcastAttributeToStyle( conversion, { modelElement: 'tableCell', modelAttribute: modelAttributes.color, styleName: 'border-color' } );
166
+ downcastAttributeToStyle( conversion, { modelElement: 'tableCell', modelAttribute: modelAttributes.width, styleName: 'border-width' } );
160
167
  }
161
168
 
162
- // Enables the `'horizontalAlignment'` attribute for table cells.
169
+ // Enables the `'tableCellHorizontalAlignment'` attribute for table cells.
163
170
  //
164
171
  // @param {module:engine/model/schema~Schema} schema
165
172
  // @param {module:engine/conversion/conversion~Conversion} conversion
@@ -167,14 +174,14 @@ function enableBorderProperties( schema, conversion, defaultBorder ) {
167
174
  // @param {String} defaultValue The default horizontal alignment value.
168
175
  function enableHorizontalAlignmentProperty( schema, conversion, defaultValue ) {
169
176
  schema.extend( 'tableCell', {
170
- allowAttributes: [ 'horizontalAlignment' ]
177
+ allowAttributes: [ 'tableCellHorizontalAlignment' ]
171
178
  } );
172
179
 
173
180
  conversion.for( 'downcast' )
174
181
  .attributeToAttribute( {
175
182
  model: {
176
183
  name: 'tableCell',
177
- key: 'horizontalAlignment'
184
+ key: 'tableCellHorizontalAlignment'
178
185
  },
179
186
  view: alignment => ( {
180
187
  key: 'style',
@@ -194,7 +201,7 @@ function enableHorizontalAlignmentProperty( schema, conversion, defaultValue ) {
194
201
  }
195
202
  },
196
203
  model: {
197
- key: 'horizontalAlignment',
204
+ key: 'tableCellHorizontalAlignment',
198
205
  value: viewElement => {
199
206
  const align = viewElement.getStyle( 'text-align' );
200
207
 
@@ -211,7 +218,7 @@ function enableHorizontalAlignmentProperty( schema, conversion, defaultValue ) {
211
218
  }
212
219
  },
213
220
  model: {
214
- key: 'horizontalAlignment',
221
+ key: 'tableCellHorizontalAlignment',
215
222
  value: viewElement => {
216
223
  const align = viewElement.getAttribute( 'align' );
217
224
 
@@ -228,14 +235,14 @@ function enableHorizontalAlignmentProperty( schema, conversion, defaultValue ) {
228
235
  // @param {String} defaultValue The default vertical alignment value.
229
236
  function enableVerticalAlignmentProperty( schema, conversion, defaultValue ) {
230
237
  schema.extend( 'tableCell', {
231
- allowAttributes: [ 'verticalAlignment' ]
238
+ allowAttributes: [ 'tableCellVerticalAlignment' ]
232
239
  } );
233
240
 
234
241
  conversion.for( 'downcast' )
235
242
  .attributeToAttribute( {
236
243
  model: {
237
244
  name: 'tableCell',
238
- key: 'verticalAlignment'
245
+ key: 'tableCellVerticalAlignment'
239
246
  },
240
247
  view: alignment => ( {
241
248
  key: 'style',
@@ -255,7 +262,7 @@ function enableVerticalAlignmentProperty( schema, conversion, defaultValue ) {
255
262
  }
256
263
  },
257
264
  model: {
258
- key: 'verticalAlignment',
265
+ key: 'tableCellVerticalAlignment',
259
266
  value: viewElement => {
260
267
  const align = viewElement.getStyle( 'vertical-align' );
261
268
 
@@ -272,7 +279,7 @@ function enableVerticalAlignmentProperty( schema, conversion, defaultValue ) {
272
279
  }
273
280
  },
274
281
  model: {
275
- key: 'verticalAlignment',
282
+ key: 'tableCellVerticalAlignment',
276
283
  value: viewElement => {
277
284
  const valign = viewElement.getAttribute( 'valign' );
278
285
 
@@ -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
 
@@ -430,6 +430,16 @@ export default class TableCellPropertiesView extends View {
430
430
  this.keystrokes.listenTo( this.element );
431
431
  }
432
432
 
433
+ /**
434
+ * @inheritDoc
435
+ */
436
+ destroy() {
437
+ super.destroy();
438
+
439
+ this.focusTracker.destroy();
440
+ this.keystrokes.destroy();
441
+ }
442
+
433
443
  /**
434
444
  * Focuses the fist focusable field in the form.
435
445
  */
@@ -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
 
@@ -12,7 +12,6 @@ import { Plugin } from 'ckeditor5/src/core';
12
12
  import TableSelection from './tableselection';
13
13
  import TableWalker from './tablewalker';
14
14
  import TableUtils from './tableutils';
15
- import { getColumnIndexes, getRowIndexes, getSelectionAffectedTableCells, isSelectionRectangular, sortRanges } from './utils/selection';
16
15
  import {
17
16
  cropTableToDimensions,
18
17
  getHorizontallyOverlappingCells,
@@ -122,7 +121,7 @@ export default class TableClipboard extends Plugin {
122
121
  return;
123
122
  }
124
123
 
125
- const selectedTableCells = getSelectionAffectedTableCells( model.document.selection );
124
+ const selectedTableCells = tableUtils.getSelectionAffectedTableCells( model.document.selection );
126
125
 
127
126
  if ( !selectedTableCells.length ) {
128
127
  removeEmptyRowsColumns( pastedTable, tableUtils );
@@ -171,7 +170,7 @@ export default class TableClipboard extends Plugin {
171
170
  if ( this.editor.plugins.get( 'TableSelection' ).isEnabled ) {
172
171
  // Selection ranges must be sorted because the first and last selection ranges are considered
173
172
  // as anchor/focus cell ranges for multi-cell selection.
174
- const selectionRanges = sortRanges( cellsToSelect.map( cell => writer.createRangeOn( cell ) ) );
173
+ const selectionRanges = tableUtils.sortRanges( cellsToSelect.map( cell => writer.createRangeOn( cell ) ) );
175
174
 
176
175
  writer.setSelection( selectionRanges );
177
176
  } else {
@@ -311,17 +310,21 @@ export default class TableClipboard extends Plugin {
311
310
 
312
311
  return cellToInsert;
313
312
  }
313
+
314
+ /**
315
+ * Extracts the table for pasting into a table.
316
+ *
317
+ * @protected
318
+ * @param {module:engine/model/documentfragment~DocumentFragment|module:engine/model/item~Item} content The content to insert.
319
+ * @param {module:engine/model/model~Model} model The editor model.
320
+ * @returns {module:engine/model/element~Element|null}
321
+ */
322
+ getTableIfOnlyTableInContent( content, model ) {
323
+ return getTableIfOnlyTableInContent( content, model );
324
+ }
314
325
  }
315
326
 
316
- /**
317
- * Extract table for pasting into table.
318
- *
319
- * @private
320
- * @param {module:engine/model/documentfragment~DocumentFragment|module:engine/model/item~Item} content The content to insert.
321
- * @param {module:engine/model/model~Model} model The editor model.
322
- * @returns {module:engine/model/element~Element|null}
323
- */
324
- export function getTableIfOnlyTableInContent( content, model ) {
327
+ function getTableIfOnlyTableInContent( content, model ) {
325
328
  if ( !content.is( 'documentFragment' ) && !content.is( 'element' ) ) {
326
329
  return null;
327
330
  }
@@ -381,8 +384,8 @@ export function getTableIfOnlyTableInContent( content, model ) {
381
384
  function prepareTableForPasting( selectedTableCells, pastedDimensions, writer, tableUtils ) {
382
385
  const selectedTable = selectedTableCells[ 0 ].findAncestor( 'table' );
383
386
 
384
- const columnIndexes = getColumnIndexes( selectedTableCells );
385
- const rowIndexes = getRowIndexes( selectedTableCells );
387
+ const columnIndexes = tableUtils.getColumnIndexes( selectedTableCells );
388
+ const rowIndexes = tableUtils.getRowIndexes( selectedTableCells );
386
389
 
387
390
  const selection = {
388
391
  firstColumn: columnIndexes.first,
@@ -403,7 +406,7 @@ function prepareTableForPasting( selectedTableCells, pastedDimensions, writer, t
403
406
 
404
407
  // In case of expanding selection we do not reset the selection so in this case we will always try to fix selection
405
408
  // like in the case of a non-rectangular area. This might be fixed by re-setting selected cells array but this shortcut is safe.
406
- if ( shouldExpandSelection || !isSelectionRectangular( selectedTableCells, tableUtils ) ) {
409
+ if ( shouldExpandSelection || !tableUtils.isSelectionRectangular( selectedTableCells ) ) {
407
410
  // For a non-rectangular selection (ie in which some cells sticks out from a virtual selection rectangle) we need to create
408
411
  // a table layout that has a rectangular selection. This will split cells so the selection become rectangular.
409
412
  // Beyond this point we will operate on fixed content table.
@@ -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,6 +62,7 @@ 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
68
  allowWhere: '$block',
@@ -88,15 +90,29 @@ export default class TableEditing extends Plugin {
88
90
  // Table conversion.
89
91
  conversion.for( 'upcast' ).add( upcastTable() );
90
92
 
91
- conversion.for( 'editingDowncast' ).add( downcastInsertTable( { asWidget: true } ) );
92
- conversion.for( 'dataDowncast' ).add( downcastInsertTable() );
93
+ conversion.for( 'editingDowncast' ).elementToStructure( {
94
+ model: {
95
+ name: 'table',
96
+ attributes: [ 'headingRows' ]
97
+ },
98
+ view: downcastTable( tableUtils, { asWidget: true } )
99
+ } );
100
+ conversion.for( 'dataDowncast' ).elementToStructure( {
101
+ model: {
102
+ name: 'table',
103
+ attributes: [ 'headingRows' ]
104
+ },
105
+ view: downcastTable( tableUtils )
106
+ } );
93
107
 
94
108
  // Table row conversion.
95
109
  conversion.for( 'upcast' ).elementToElement( { model: 'tableRow', view: 'tr' } );
96
110
  conversion.for( 'upcast' ).add( skipEmptyTableRow() );
97
111
 
98
- conversion.for( 'editingDowncast' ).add( downcastInsertRow() );
99
- conversion.for( 'editingDowncast' ).add( downcastRemoveRow() );
112
+ conversion.for( 'downcast' ).elementToElement( {
113
+ model: 'tableRow',
114
+ view: downcastRow()
115
+ } );
100
116
 
101
117
  // Table cell conversion.
102
118
  conversion.for( 'upcast' ).elementToElement( { model: 'tableCell', view: 'td' } );
@@ -104,12 +120,24 @@ export default class TableEditing extends Plugin {
104
120
  conversion.for( 'upcast' ).add( ensureParagraphInTableCell( 'td' ) );
105
121
  conversion.for( 'upcast' ).add( ensureParagraphInTableCell( 'th' ) );
106
122
 
107
- conversion.for( 'editingDowncast' ).add( downcastInsertCell() );
123
+ conversion.for( 'editingDowncast' ).elementToElement( {
124
+ model: 'tableCell',
125
+ view: downcastCell( { asWidget: true } )
126
+ } );
127
+ conversion.for( 'dataDowncast' ).elementToElement( {
128
+ model: 'tableCell',
129
+ view: downcastCell()
130
+ } );
108
131
 
109
132
  // Duplicates code - needed to properly refresh paragraph inside a table cell.
110
133
  conversion.for( 'editingDowncast' ).elementToElement( {
111
134
  model: 'paragraph',
112
- view: convertParagraphInTableCell,
135
+ view: convertParagraphInTableCell( { asWidget: true } ),
136
+ converterPriority: 'high'
137
+ } );
138
+ conversion.for( 'dataDowncast' ).elementToElement( {
139
+ model: 'paragraph',
140
+ view: convertParagraphInTableCell(),
113
141
  converterPriority: 'high'
114
142
  } );
115
143
 
@@ -126,9 +154,6 @@ export default class TableEditing extends Plugin {
126
154
  view: 'rowspan'
127
155
  } );
128
156
 
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
157
  // Manually adjust model position mappings in a special case, when a table cell contains a paragraph, which is bound
133
158
  // to its parent (to the table cell). This custom model-to-view position mapping is necessary in data pipeline only,
134
159
  // because only during this conversion a paragraph can be bound to its parent.
@@ -164,17 +189,13 @@ export default class TableEditing extends Plugin {
164
189
  editor.commands.add( 'selectTableRow', new SelectRowCommand( editor ) );
165
190
  editor.commands.add( 'selectTableColumn', new SelectColumnCommand( editor ) );
166
191
 
167
- injectTableHeadingRowsRefreshPostFixer( model );
168
192
  injectTableLayoutPostFixer( model );
169
- injectTableCellRefreshPostFixer( model, editor.editing.mapper );
170
193
  injectTableCellParagraphPostFixer( model );
171
- }
172
194
 
173
- /**
174
- * @inheritDoc
175
- */
176
- static get requires() {
177
- return [ TableUtils ];
195
+ this.listenTo( model.document, 'change:data', () => {
196
+ tableHeadingsRefreshHandler( model, editor.editing );
197
+ tableCellRefreshHandler( model, editor.editing );
198
+ } );
178
199
  }
179
200
  }
180
201
 
@@ -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
  /**
@@ -83,10 +83,11 @@ export default class TableKeyboard extends Plugin {
83
83
  */
84
84
  _getTabHandler( isForward ) {
85
85
  const editor = this.editor;
86
+ const tableUtils = this.editor.plugins.get( TableUtils );
86
87
 
87
88
  return ( domEventData, cancel ) => {
88
89
  const selection = editor.model.document.selection;
89
- let tableCell = getTableCellsContainingSelection( selection )[ 0 ];
90
+ let tableCell = tableUtils.getTableCellsContainingSelection( selection )[ 0 ];
90
91
 
91
92
  if ( !tableCell ) {
92
93
  tableCell = this.editor.plugins.get( 'TableSelection' ).getFocusCell();
@@ -115,7 +116,6 @@ export default class TableKeyboard extends Plugin {
115
116
  return;
116
117
  }
117
118
 
118
- const tableUtils = this.editor.plugins.get( 'TableUtils' );
119
119
  const isLastCellInRow = currentCellIndex === tableRow.childCount - 1;
120
120
  const isLastRow = currentRowIndex === tableUtils.getRows( table ) - 1;
121
121
 
@@ -188,13 +188,14 @@ export default class TableKeyboard extends Plugin {
188
188
  * @returns {Boolean} Returns `true` if key was handled.
189
189
  */
190
190
  _handleArrowKeys( direction, expandSelection ) {
191
+ const tableUtils = this.editor.plugins.get( TableUtils );
191
192
  const model = this.editor.model;
192
193
  const selection = model.document.selection;
193
194
  const isForward = [ 'right', 'down' ].includes( direction );
194
195
 
195
196
  // In case one or more table cells are selected (from outside),
196
197
  // move the selection to a cell adjacent to the selected table fragment.
197
- const selectedCells = getSelectedTableCells( selection );
198
+ const selectedCells = tableUtils.getSelectedTableCells( selection );
198
199
 
199
200
  if ( selectedCells.length ) {
200
201
  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
 
@@ -31,6 +31,6 @@ export default class TableAlignmentCommand extends TablePropertyCommand {
31
31
  * @param {String} defaultValue The default value for the "alignment" attribute.
32
32
  */
33
33
  constructor( editor, defaultValue ) {
34
- super( editor, 'alignment', defaultValue );
34
+ super( editor, 'tableAlignment', defaultValue );
35
35
  }
36
36
  }
@@ -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
 
@@ -31,6 +31,6 @@ export default class TableBackgroundColorCommand extends TablePropertyCommand {
31
31
  * @param {String} defaultValue The default value of the attribute.
32
32
  */
33
33
  constructor( editor, defaultValue ) {
34
- super( editor, 'backgroundColor', defaultValue );
34
+ super( editor, 'tableBackgroundColor', defaultValue );
35
35
  }
36
36
  }
@@ -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
 
@@ -32,7 +32,7 @@ export default class TableBorderColorCommand extends TablePropertyCommand {
32
32
  * @param {String} defaultValue The default value of the attribute.
33
33
  */
34
34
  constructor( editor, defaultValue ) {
35
- super( editor, 'borderColor', defaultValue );
35
+ super( editor, 'tableBorderColor', defaultValue );
36
36
  }
37
37
 
38
38
  /**
@@ -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
 
@@ -32,7 +32,7 @@ export default class TableBorderStyleCommand extends TablePropertyCommand {
32
32
  * @param {String} defaultValue The default value of the attribute.
33
33
  */
34
34
  constructor( editor, defaultValue ) {
35
- super( editor, 'borderStyle', defaultValue );
35
+ super( editor, 'tableBorderStyle', defaultValue );
36
36
  }
37
37
 
38
38
  /**
@@ -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
 
@@ -40,7 +40,7 @@ export default class TableBorderWidthCommand extends TablePropertyCommand {
40
40
  * @param {String} defaultValue The default value of the attribute.
41
41
  */
42
42
  constructor( editor, defaultValue ) {
43
- super( editor, 'borderWidth', defaultValue );
43
+ super( editor, 'tableBorderWidth', defaultValue );
44
44
  }
45
45
 
46
46
  /**