@ckeditor/ckeditor5-table 27.1.0 → 29.2.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 (156) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +3 -3
  3. package/build/table.js +1 -1
  4. package/build/translations/ar.js +1 -0
  5. package/build/translations/az.js +1 -0
  6. package/build/translations/bg.js +1 -0
  7. package/build/translations/cs.js +1 -0
  8. package/build/translations/da.js +1 -0
  9. package/build/translations/de-ch.js +1 -0
  10. package/build/translations/de.js +1 -0
  11. package/build/translations/en-au.js +1 -0
  12. package/build/translations/en-gb.js +1 -0
  13. package/build/translations/es.js +1 -0
  14. package/build/translations/et.js +1 -0
  15. package/build/translations/fa.js +1 -0
  16. package/build/translations/fi.js +1 -0
  17. package/build/translations/fr.js +1 -0
  18. package/build/translations/gl.js +1 -0
  19. package/build/translations/hi.js +1 -0
  20. package/build/translations/hr.js +1 -0
  21. package/build/translations/hu.js +1 -0
  22. package/build/translations/id.js +1 -0
  23. package/build/translations/it.js +1 -0
  24. package/build/translations/ja.js +1 -0
  25. package/build/translations/ko.js +1 -0
  26. package/build/translations/ku.js +1 -0
  27. package/build/translations/lt.js +1 -0
  28. package/build/translations/lv.js +1 -0
  29. package/build/translations/nb.js +1 -0
  30. package/build/translations/ne.js +1 -0
  31. package/build/translations/nl.js +1 -0
  32. package/build/translations/no.js +1 -0
  33. package/build/translations/pl.js +1 -0
  34. package/build/translations/pt-br.js +1 -0
  35. package/build/translations/ro.js +1 -0
  36. package/build/translations/ru.js +1 -0
  37. package/build/translations/sk.js +1 -0
  38. package/build/translations/sq.js +1 -0
  39. package/build/translations/sr-latn.js +1 -0
  40. package/build/translations/sr.js +1 -0
  41. package/build/translations/sv.js +1 -0
  42. package/build/translations/th.js +1 -0
  43. package/build/translations/tk.js +1 -0
  44. package/build/translations/tr.js +1 -0
  45. package/build/translations/ug.js +1 -0
  46. package/build/translations/uk.js +1 -0
  47. package/build/translations/vi.js +1 -0
  48. package/build/translations/zh-cn.js +1 -0
  49. package/build/translations/zh.js +1 -0
  50. package/ckeditor5-metadata.json +174 -0
  51. package/lang/contexts.json +4 -1
  52. package/lang/translations/ar.po +12 -0
  53. package/lang/translations/az.po +12 -0
  54. package/lang/translations/bg.po +12 -0
  55. package/lang/translations/cs.po +12 -0
  56. package/lang/translations/da.po +12 -0
  57. package/lang/translations/de-ch.po +12 -0
  58. package/lang/translations/de.po +12 -0
  59. package/lang/translations/en-au.po +12 -0
  60. package/lang/translations/en-gb.po +12 -0
  61. package/lang/translations/en.po +12 -0
  62. package/lang/translations/es.po +12 -0
  63. package/lang/translations/et.po +12 -0
  64. package/lang/translations/fa.po +12 -0
  65. package/lang/translations/fi.po +12 -0
  66. package/lang/translations/fr.po +12 -0
  67. package/lang/translations/gl.po +12 -0
  68. package/lang/translations/hi.po +12 -0
  69. package/lang/translations/hr.po +12 -0
  70. package/lang/translations/hu.po +23 -11
  71. package/lang/translations/id.po +23 -11
  72. package/lang/translations/it.po +12 -0
  73. package/lang/translations/ja.po +12 -0
  74. package/lang/translations/ko.po +12 -0
  75. package/lang/translations/ku.po +12 -0
  76. package/lang/translations/lt.po +12 -0
  77. package/lang/translations/lv.po +12 -0
  78. package/lang/translations/nb.po +12 -0
  79. package/lang/translations/ne.po +12 -0
  80. package/lang/translations/nl.po +12 -0
  81. package/lang/translations/no.po +12 -0
  82. package/lang/translations/pl.po +12 -0
  83. package/lang/translations/pt-br.po +12 -0
  84. package/lang/translations/ro.po +51 -39
  85. package/lang/translations/ru.po +12 -0
  86. package/lang/translations/sk.po +12 -0
  87. package/lang/translations/sq.po +12 -0
  88. package/lang/translations/sr-latn.po +12 -0
  89. package/lang/translations/sr.po +12 -0
  90. package/lang/translations/sv.po +12 -0
  91. package/lang/translations/th.po +12 -0
  92. package/lang/translations/tk.po +12 -0
  93. package/lang/translations/tr.po +12 -0
  94. package/lang/translations/ug.po +12 -0
  95. package/lang/translations/uk.po +12 -0
  96. package/lang/translations/vi.po +12 -0
  97. package/lang/translations/zh-cn.po +12 -0
  98. package/lang/translations/zh.po +12 -0
  99. package/package.json +25 -23
  100. package/src/commands/insertcolumncommand.js +2 -3
  101. package/src/commands/insertrowcommand.js +2 -3
  102. package/src/commands/inserttablecommand.js +22 -7
  103. package/src/commands/mergecellcommand.js +5 -3
  104. package/src/commands/removerowcommand.js +8 -5
  105. package/src/converters/downcast.js +4 -5
  106. package/src/converters/table-caption-post-fixer.js +69 -0
  107. package/src/converters/table-cell-paragraph-post-fixer.js +3 -1
  108. package/src/converters/table-layout-post-fixer.js +13 -8
  109. package/src/converters/tableproperties.js +82 -23
  110. package/src/converters/upcasttable.js +63 -0
  111. package/src/index.js +18 -33
  112. package/src/table.js +17 -0
  113. package/src/tablecaption/tablecaptionediting.js +153 -0
  114. package/src/tablecaption/tablecaptionui.js +71 -0
  115. package/src/tablecaption/toggletablecaptioncommand.js +120 -0
  116. package/src/tablecaption/utils.js +93 -0
  117. package/src/tablecaption.js +35 -0
  118. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +3 -2
  119. package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +10 -3
  120. package/src/tablecellproperties/commands/tablecellborderstylecommand.js +10 -3
  121. package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +17 -4
  122. package/src/tablecellproperties/commands/tablecellheightcommand.js +10 -3
  123. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +3 -2
  124. package/src/tablecellproperties/commands/tablecellpaddingcommand.js +17 -4
  125. package/src/tablecellproperties/commands/tablecellpropertycommand.js +28 -2
  126. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +3 -2
  127. package/src/tablecellproperties/commands/tablecellwidthcommand.js +10 -3
  128. package/src/tablecellproperties/tablecellpropertiesediting.js +164 -65
  129. package/src/tablecellproperties/tablecellpropertiesui.js +76 -16
  130. package/src/tablecellproperties/ui/tablecellpropertiesview.js +39 -13
  131. package/src/tablecellproperties.js +42 -2
  132. package/src/tableediting.js +76 -6
  133. package/src/tablekeyboard.js +3 -2
  134. package/src/tableproperties/commands/tablealignmentcommand.js +3 -2
  135. package/src/tableproperties/commands/tablebackgroundcolorcommand.js +3 -2
  136. package/src/tableproperties/commands/tablebordercolorcommand.js +10 -3
  137. package/src/tableproperties/commands/tableborderstylecommand.js +10 -3
  138. package/src/tableproperties/commands/tableborderwidthcommand.js +17 -4
  139. package/src/tableproperties/commands/tableheightcommand.js +10 -3
  140. package/src/tableproperties/commands/tablepropertycommand.js +28 -2
  141. package/src/tableproperties/commands/tablewidthcommand.js +10 -3
  142. package/src/tableproperties/tablepropertiesediting.js +104 -47
  143. package/src/tableproperties/tablepropertiesui.js +68 -15
  144. package/src/tableproperties/ui/tablepropertiesview.js +26 -11
  145. package/src/tableproperties.js +38 -2
  146. package/src/tableui.js +10 -1
  147. package/src/tableutils.js +41 -5
  148. package/src/tablewalker.js +36 -1
  149. package/src/ui/colorinputview.js +11 -7
  150. package/src/utils/structure.js +4 -3
  151. package/src/utils/table-properties.js +41 -0
  152. package/src/utils/ui/table-properties.js +29 -7
  153. package/src/utils/ui/widget.js +7 -15
  154. package/theme/table.css +17 -1
  155. package/theme/tablecaption.css +53 -0
  156. package/build/table.js.map +0 -1
package/src/tableutils.js CHANGED
@@ -7,6 +7,7 @@
7
7
  * @module table/tableutils
8
8
  */
9
9
 
10
+ import { CKEditorError } from 'ckeditor5/src/utils';
10
11
  import { Plugin } from 'ckeditor5/src/core';
11
12
 
12
13
  import TableWalker from './tablewalker';
@@ -105,11 +106,11 @@ export default class TableUtils extends Plugin {
105
106
  createEmptyRows( writer, table, 0, rows, columns );
106
107
 
107
108
  if ( options.headingRows ) {
108
- updateNumericAttribute( 'headingRows', options.headingRows, table, writer, 0 );
109
+ updateNumericAttribute( 'headingRows', Math.min( options.headingRows, rows ), table, writer, 0 );
109
110
  }
110
111
 
111
112
  if ( options.headingColumns ) {
112
- updateNumericAttribute( 'headingColumns', options.headingColumns, table, writer, 0 );
113
+ updateNumericAttribute( 'headingColumns', Math.min( options.headingColumns, columns ), table, writer, 0 );
113
114
  }
114
115
 
115
116
  return table;
@@ -153,6 +154,19 @@ export default class TableUtils extends Plugin {
153
154
  const rows = this.getRows( table );
154
155
  const columns = this.getColumns( table );
155
156
 
157
+ if ( insertAt > rows ) {
158
+ /**
159
+ * The `options.at` points at a row position that does not exist.
160
+ *
161
+ * @error tableutils-insertrows-insert-out-of-range
162
+ */
163
+ throw new CKEditorError(
164
+ 'tableutils-insertrows-insert-out-of-range',
165
+ this,
166
+ { options }
167
+ );
168
+ }
169
+
156
170
  model.change( writer => {
157
171
  const headingRows = table.getAttribute( 'headingRows' ) || 0;
158
172
 
@@ -261,6 +275,11 @@ export default class TableUtils extends Plugin {
261
275
  // Inserting at the end and at the beginning of a table doesn't require to calculate anything special.
262
276
  if ( insertAt === 0 || tableColumns === insertAt ) {
263
277
  for ( const tableRow of table.getChildren() ) {
278
+ // Ignore non-row elements inside the table (e.g. caption).
279
+ if ( !tableRow.is( 'element', 'tableRow' ) ) {
280
+ continue;
281
+ }
282
+
264
283
  createCells( columnsToInsert, writer, writer.createPositionAt( tableRow, insertAt ? 'end' : 0 ) );
265
284
  }
266
285
 
@@ -329,9 +348,23 @@ export default class TableUtils extends Plugin {
329
348
  const model = this.editor.model;
330
349
 
331
350
  const rowsToRemove = options.rows || 1;
351
+ const rowCount = this.getRows( table );
332
352
  const first = options.at;
333
353
  const last = first + rowsToRemove - 1;
334
354
 
355
+ if ( last > rowCount - 1 ) {
356
+ /**
357
+ * The `options.at` param must point at existing row and `options.rows` must not exceed the rows in the table.
358
+ *
359
+ * @error tableutils-removerows-row-index-out-of-range
360
+ */
361
+ throw new CKEditorError(
362
+ 'tableutils-removerows-row-index-out-of-range',
363
+ this,
364
+ { table, options }
365
+ );
366
+ }
367
+
335
368
  model.change( writer => {
336
369
  // Removing rows from the table require that most calculations to be done prior to changing table structure.
337
370
  // Preparations must be done in the same enqueueChange callback to use the current table structure.
@@ -718,6 +751,8 @@ export default class TableUtils extends Plugin {
718
751
  */
719
752
  getColumns( table ) {
720
753
  // Analyze first row only as all the rows should have the same width.
754
+ // Using the first row without checking if it's a tableRow because we expect
755
+ // that table will have only tableRow model elements at the beginning.
721
756
  const row = table.getChild( 0 );
722
757
 
723
758
  return [ ...row.getChildren() ].reduce( ( columns, row ) => {
@@ -728,7 +763,7 @@ export default class TableUtils extends Plugin {
728
763
  }
729
764
 
730
765
  /**
731
- * Returns the number of rows for a given table.
766
+ * Returns the number of rows for a given table. Any other element present in the table model is omitted.
732
767
  *
733
768
  * editor.plugins.get( 'TableUtils' ).getRows( table );
734
769
  *
@@ -736,8 +771,9 @@ export default class TableUtils extends Plugin {
736
771
  * @returns {Number}
737
772
  */
738
773
  getRows( table ) {
739
- // Simple row counting, not including rowspan due to #6427.
740
- return table.childCount;
774
+ // Rowspan not included due to #6427.
775
+ return Array.from( table.getChildren() )
776
+ .reduce( ( rowCount, child ) => child.is( 'element', 'tableRow' ) ? rowCount + 1 : rowCount, 0 );
741
777
  }
742
778
  }
743
779
 
@@ -159,6 +159,14 @@ export default class TableWalker {
159
159
  */
160
160
  this._row = 0;
161
161
 
162
+ /**
163
+ * The index of the current row element in the table.
164
+ *
165
+ * @type {Number}
166
+ * @protected
167
+ */
168
+ this._rowIndex = 0;
169
+
162
170
  /**
163
171
  * The current column index.
164
172
  *
@@ -209,13 +217,20 @@ export default class TableWalker {
209
217
  * @returns {module:table/tablewalker~TableSlot} The next table walker's value.
210
218
  */
211
219
  next() {
212
- const row = this._table.getChild( this._row );
220
+ const row = this._table.getChild( this._rowIndex );
213
221
 
214
222
  // Iterator is done when there's no row (table ended) or the row is after `endRow` limit.
215
223
  if ( !row || this._isOverEndRow() ) {
216
224
  return { done: true };
217
225
  }
218
226
 
227
+ // We step over current element when it is not a tableRow instance.
228
+ if ( !row.is( 'element', 'tableRow' ) ) {
229
+ this._rowIndex++;
230
+
231
+ return this.next();
232
+ }
233
+
219
234
  if ( this._isOverEndColumn() ) {
220
235
  return this._advanceToNextRow();
221
236
  }
@@ -280,6 +295,7 @@ export default class TableWalker {
280
295
  */
281
296
  _advanceToNextRow() {
282
297
  this._row++;
298
+ this._rowIndex++;
283
299
  this._column = 0;
284
300
  this._cellIndex = 0;
285
301
  this._nextCellAtColumn = -1;
@@ -465,6 +481,15 @@ class TableSlot {
465
481
  */
466
482
  this._cellIndex = tableWalker._cellIndex;
467
483
 
484
+ /**
485
+ * The index of the current row element in the table.
486
+ *
487
+ * @readonly
488
+ * @member {Number}
489
+ * @private
490
+ */
491
+ this._rowIndex = tableWalker._rowIndex;
492
+
468
493
  /**
469
494
  * The table element.
470
495
  *
@@ -505,6 +530,16 @@ class TableSlot {
505
530
  return parseInt( this.cell.getAttribute( 'rowspan' ) || 1 );
506
531
  }
507
532
 
533
+ /**
534
+ * The index of the current row element in the table.
535
+ *
536
+ * @readonly
537
+ * @returns {Number}
538
+ */
539
+ get rowIndex() {
540
+ return this._rowIndex;
541
+ }
542
+
508
543
  /**
509
544
  * Returns the {@link module:engine/model/position~Position} before the table slot.
510
545
  *
@@ -25,9 +25,11 @@ export default class ColorInputView extends View {
25
25
  *
26
26
  * @param {module:utils/locale~Locale} locale The locale instance.
27
27
  * @param {Object} options The input options.
28
- * @param {module:ui/colorgrid/colorgrid~ColorDefinition} options.colorDefinitions The colors to be displayed
28
+ * @param {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>} options.colorDefinitions The colors to be displayed
29
29
  * in the palette inside the input's dropdown.
30
30
  * @param {Number} options.columns The number of columns in which the colors will be displayed.
31
+ * @param {String} [options.defaultColorValue] If specified, the color input view will replace the "Remove color" button with
32
+ * the "Restore default" button. Instead of clearing the input field, the default color value will be set.
31
33
  */
32
34
  constructor( locale, options ) {
33
35
  super( locale );
@@ -96,7 +98,7 @@ export default class ColorInputView extends View {
96
98
  * some error, it helps screen readers read the error text.
97
99
  *
98
100
  * @observable
99
- * @member {Boolean} #ariaDescribedById
101
+ * @member {String} #ariaDescribedById
100
102
  */
101
103
  this.set( 'ariaDescribedById' );
102
104
 
@@ -113,7 +115,7 @@ export default class ColorInputView extends View {
113
115
  * @protected
114
116
  * @member {module:ui/dropdown/dropdown~DropdownView}
115
117
  */
116
- this._dropdownView = this._createDropdownView( locale );
118
+ this._dropdownView = this._createDropdownView();
117
119
 
118
120
  /**
119
121
  * An instance of the input allowing the user to type a color value.
@@ -121,7 +123,7 @@ export default class ColorInputView extends View {
121
123
  * @protected
122
124
  * @member {module:ui/inputtext/inputtextview~InputTextView}
123
125
  */
124
- this._inputView = this._createInputTextView( locale );
126
+ this._inputView = this._createInputTextView();
125
127
 
126
128
  /**
127
129
  * The flag that indicates whether the user is still typing.
@@ -173,7 +175,7 @@ export default class ColorInputView extends View {
173
175
  const colorGrid = this._createColorGrid( locale );
174
176
  const dropdown = createDropdown( locale );
175
177
  const colorPreview = new View();
176
- const removeColorButton = this._createRemoveColorButton( locale );
178
+ const removeColorButton = this._createRemoveColorButton();
177
179
 
178
180
  colorPreview.setTemplate( {
179
181
  tag: 'span',
@@ -263,13 +265,15 @@ export default class ColorInputView extends View {
263
265
  const locale = this.locale;
264
266
  const t = locale.t;
265
267
  const removeColorButton = new ButtonView( locale );
268
+ const defaultColor = this.options.defaultColorValue || '';
269
+ const removeColorButtonLabel = defaultColor ? t( 'Restore default' ) : t( 'Remove color' );
266
270
 
267
271
  removeColorButton.class = 'ck-input-color__remove-color';
268
272
  removeColorButton.withText = true;
269
273
  removeColorButton.icon = icons.eraser;
270
- removeColorButton.label = t( 'Remove color' );
274
+ removeColorButton.label = removeColorButtonLabel;
271
275
  removeColorButton.on( 'execute', () => {
272
- this.value = '';
276
+ this.value = defaultColor;
273
277
  this._dropdownView.isOpen = false;
274
278
  this.fire( 'input' );
275
279
  } );
@@ -17,8 +17,8 @@ import { createEmptyTableCell, updateNumericAttribute } from './common';
17
17
  *
18
18
  * const croppedTable = cropTableToDimensions( table, {
19
19
  * startRow: 1,
20
- * endRow: 1,
21
- * startColumn: 3,
20
+ * endRow: 3,
21
+ * startColumn: 1,
22
22
  * endColumn: 3
23
23
  * }, writer );
24
24
  *
@@ -396,8 +396,9 @@ export function removeEmptyColumns( table, tableUtils ) {
396
396
  */
397
397
  export function removeEmptyRows( table, tableUtils ) {
398
398
  const emptyRows = [];
399
+ const tableRowCount = tableUtils.getRows( table );
399
400
 
400
- for ( let rowIndex = 0; rowIndex < table.childCount; rowIndex++ ) {
401
+ for ( let rowIndex = 0; rowIndex < tableRowCount; rowIndex++ ) {
401
402
  const tableRow = table.getChild( rowIndex );
402
403
 
403
404
  if ( tableRow.isEmpty ) {
@@ -64,3 +64,44 @@ export function addDefaultUnitToNumericValue( value, defaultUnit ) {
64
64
 
65
65
  return `${ numericValue }${ defaultUnit }`;
66
66
  }
67
+
68
+ /**
69
+ * Returns the normalized configuration.
70
+ *
71
+ * @param {Object} config
72
+ * @param {Object} [options={}]
73
+ * @param {Boolean} [options.includeAlignmentProperty=false] Whether the "alignment" property should be added.
74
+ * @param {Boolean} [options.includePaddingProperty=false] Whether the "padding" property should be added.
75
+ * @param {Boolean} [options.includeVerticalAlignmentProperty=false] Whether the "verticalAlignment" property should be added.
76
+ * @param {Boolean} [options.includeHorizontalAlignmentProperty=false] Whether the "horizontalAlignment" property should be added.
77
+ * @param {Boolean} [options.isRightToLeftContent=false] Whether the content is right-to-left.
78
+ * @returns {Object}
79
+ */
80
+ export function getNormalizedDefaultProperties( config, options = {} ) {
81
+ const normalizedConfig = Object.assign( {
82
+ borderStyle: 'none',
83
+ borderWidth: '',
84
+ borderColor: '',
85
+ backgroundColor: '',
86
+ width: '',
87
+ height: ''
88
+ }, config );
89
+
90
+ if ( options.includeAlignmentProperty && !normalizedConfig.alignment ) {
91
+ normalizedConfig.alignment = 'center';
92
+ }
93
+
94
+ if ( options.includePaddingProperty && !normalizedConfig.padding ) {
95
+ normalizedConfig.padding = '';
96
+ }
97
+
98
+ if ( options.includeVerticalAlignmentProperty && !normalizedConfig.verticalAlignment ) {
99
+ normalizedConfig.verticalAlignment = 'middle';
100
+ }
101
+
102
+ if ( options.includeHorizontalAlignmentProperty && !normalizedConfig.horizontalAlignment ) {
103
+ normalizedConfig.horizontalAlignment = options.isRightToLeftContent ? 'right' : 'left';
104
+ }
105
+
106
+ return normalizedConfig;
107
+ }
@@ -113,9 +113,10 @@ export function lineWidthFieldValidator( value ) {
113
113
  *
114
114
  * @param {module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView|
115
115
  * module:table/tableproperties/ui/tablepropertiesview~TablePropertiesView} view
116
+ * @param {String} defaultStyle The default border.
116
117
  * @returns {Iterable.<module:ui/dropdown/utils~ListDropdownItemDefinition>}
117
118
  */
118
- export function getBorderStyleDefinitions( view ) {
119
+ export function getBorderStyleDefinitions( view, defaultStyle ) {
119
120
  const itemDefinitions = new Collection();
120
121
  const styleLabels = getBorderStyleLabels( view.t );
121
122
 
@@ -123,14 +124,20 @@ export function getBorderStyleDefinitions( view ) {
123
124
  const definition = {
124
125
  type: 'button',
125
126
  model: new Model( {
126
- _borderStyleValue: style === 'none' ? '' : style,
127
+ _borderStyleValue: style,
127
128
  label: styleLabels[ style ],
128
129
  withText: true
129
130
  } )
130
131
  };
131
132
 
132
133
  if ( style === 'none' ) {
133
- definition.model.bind( 'isOn' ).to( view, 'borderStyle', value => !value );
134
+ definition.model.bind( 'isOn' ).to( view, 'borderStyle', value => {
135
+ if ( defaultStyle === 'none' ) {
136
+ return !value;
137
+ }
138
+
139
+ return value === style;
140
+ } );
134
141
  } else {
135
142
  definition.model.bind( 'isOn' ).to( view, 'borderStyle', value => {
136
143
  return value === style;
@@ -159,7 +166,8 @@ export function getBorderStyleDefinitions( view ) {
159
166
  * @param {String} propertyName
160
167
  * @param {Function} nameToValue A function that maps a button name to a value. By default names are the same as values.
161
168
  */
162
- export function fillToolbar( { view, icons, toolbar, labels, propertyName, nameToValue } ) {
169
+ export function fillToolbar( options ) {
170
+ const { view, icons, toolbar, labels, propertyName, nameToValue, defaultValue } = options;
163
171
  for ( const name in labels ) {
164
172
  const button = new ButtonView( view.locale );
165
173
 
@@ -169,12 +177,23 @@ export function fillToolbar( { view, icons, toolbar, labels, propertyName, nameT
169
177
  tooltip: labels[ name ]
170
178
  } );
171
179
 
180
+ // If specified the `nameToValue()` callback, map the value based on the option's name.
181
+ const buttonValue = nameToValue ? nameToValue( name ) : name;
182
+
172
183
  button.bind( 'isOn' ).to( view, propertyName, value => {
173
- return value === nameToValue( name );
184
+ // `value` comes from `view[ propertyName ]`.
185
+ let valueToCompare = value;
186
+
187
+ // If it's empty, and the `defaultValue` is specified, use it instead.
188
+ if ( value === '' && defaultValue ) {
189
+ valueToCompare = defaultValue;
190
+ }
191
+
192
+ return buttonValue === valueToCompare;
174
193
  } );
175
194
 
176
195
  button.on( 'execute', () => {
177
- view[ propertyName ] = nameToValue( name );
196
+ view[ propertyName ] = buttonValue;
178
197
  } );
179
198
 
180
199
  toolbar.items.add( button );
@@ -347,13 +366,16 @@ export const defaultColors = [
347
366
  * displayed in the input's dropdown.
348
367
  * @param {Number} options.columns The configuration of the number of columns the color palette consists of
349
368
  * in the input's dropdown.
369
+ * @param {String} [options.defaultColorValue] If specified, the color input view will replace the "Remove color" button with
370
+ * the "Restore default" button. Instead of clearing the input field, the default color value will be set.
350
371
  * @returns {Function}
351
372
  */
352
373
  export function getLabeledColorInputCreator( options ) {
353
374
  return ( labeledFieldView, viewUid, statusUid ) => {
354
375
  const inputView = new ColorInputView( labeledFieldView.locale, {
355
376
  colorDefinitions: colorConfigToColorGridDefinitions( options.colorConfig ),
356
- columns: options.columns
377
+ columns: options.columns,
378
+ defaultColorValue: options.defaultColorValue
357
379
  } );
358
380
 
359
381
  inputView.set( {
@@ -32,10 +32,14 @@ export function getSelectedTableWidget( selection ) {
32
32
  * @returns {module:engine/view/element~Element|null}
33
33
  */
34
34
  export function getTableWidgetAncestor( selection ) {
35
- const parentTable = findAncestor( 'table', selection.getFirstPosition() );
35
+ let parent = selection.getFirstPosition().parent;
36
36
 
37
- if ( parentTable && isTableWidget( parentTable.parent ) ) {
38
- return parentTable.parent;
37
+ while ( parent ) {
38
+ if ( parent.is( 'element' ) && isTableWidget( parent ) ) {
39
+ return parent;
40
+ }
41
+
42
+ parent = parent.parent;
39
43
  }
40
44
 
41
45
  return null;
@@ -48,15 +52,3 @@ export function getTableWidgetAncestor( selection ) {
48
52
  function isTableWidget( viewElement ) {
49
53
  return !!viewElement.getCustomProperty( 'table' ) && isWidget( viewElement );
50
54
  }
51
-
52
- function findAncestor( parentName, positionOrElement ) {
53
- let parent = positionOrElement.parent;
54
-
55
- while ( parent ) {
56
- if ( parent.name === parentName ) {
57
- return parent;
58
- }
59
-
60
- parent = parent.parent;
61
- }
62
- }
package/theme/table.css CHANGED
@@ -5,7 +5,9 @@
5
5
 
6
6
  .ck-content .table {
7
7
  /* Give the table widget some air and center it horizontally */
8
- margin: 1em auto;
8
+ /* The first value should be equal to --ck-spacing-large variable if used in the editor context
9
+ to avoid the content jumping (See https://github.com/ckeditor/ckeditor5/issues/9825). */
10
+ margin: 0.9em auto;
9
11
  display: table;
10
12
 
11
13
  & table {
@@ -49,3 +51,17 @@ when content is available outside the ediitor. See https://github.com/ckeditor/c
49
51
  .ck-content[dir="ltr"] .table th {
50
52
  text-align: left;
51
53
  }
54
+
55
+ .ck-editor__editable .ck-table-bogus-paragraph {
56
+ /*
57
+ * Use display:inline-block to force Chrome/Safari to limit text mutations to this element.
58
+ * See https://github.com/ckeditor/ckeditor5/issues/6062.
59
+ */
60
+ display: inline-block;
61
+
62
+ /*
63
+ * Inline HTML elements nested in the span should always be dimensioned in relation to the whole cell width.
64
+ * See https://github.com/ckeditor/ckeditor5/issues/9117.
65
+ */
66
+ width: 100%;
67
+ }
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ :root {
7
+ --ck-color-table-caption-background: hsl(0, 0%, 97%);
8
+ --ck-color-table-caption-text: hsl(0, 0%, 20%);
9
+ --ck-color-table-caption-highlighted-background: hsl(52deg 100% 50%);
10
+ }
11
+
12
+ /* Content styles */
13
+ .ck-content .table > figcaption {
14
+ display: table-caption;
15
+ caption-side: top;
16
+ word-break: break-word;
17
+ text-align: center;
18
+ color: var(--ck-color-table-caption-text);
19
+ background-color: var(--ck-color-table-caption-background);
20
+ padding: .6em;
21
+ font-size: .75em;
22
+ outline-offset: -1px;
23
+ }
24
+
25
+ /* Editing styles */
26
+ .ck.ck-editor__editable .table > figcaption {
27
+ &.table__caption_highlighted {
28
+ animation: ck-table-caption-highlight .6s ease-out;
29
+ }
30
+
31
+ &.ck-placeholder::before {
32
+ padding-left: inherit;
33
+ padding-right: inherit;
34
+
35
+ /*
36
+ * Make sure the table caption placeholder doesn't overflow the placeholder area.
37
+ * See https://github.com/ckeditor/ckeditor5/issues/9162.
38
+ */
39
+ white-space: nowrap;
40
+ overflow: hidden;
41
+ text-overflow: ellipsis;
42
+ }
43
+ }
44
+
45
+ @keyframes ck-table-caption-highlight {
46
+ 0% {
47
+ background-color: var(--ck-color-table-caption-highlighted-background);
48
+ }
49
+
50
+ 100% {
51
+ background-color: var(--ck-color-table-caption-background);
52
+ }
53
+ }