@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
@@ -29,9 +29,10 @@ export default class TableCellBorderStyleCommand extends TableCellPropertyComman
29
29
  * Creates a new `TableCellBorderStyleCommand` instance.
30
30
  *
31
31
  * @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
32
+ * @param {String} defaultValue The default value of the attribute.
32
33
  */
33
- constructor( editor ) {
34
- super( editor, 'borderStyle' );
34
+ constructor( editor, defaultValue ) {
35
+ super( editor, 'borderStyle', defaultValue );
35
36
  }
36
37
 
37
38
  /**
@@ -42,6 +43,12 @@ export default class TableCellBorderStyleCommand extends TableCellPropertyComman
42
43
  return;
43
44
  }
44
45
 
45
- return getSingleValue( tableCell.getAttribute( this.attributeName ) );
46
+ const value = getSingleValue( tableCell.getAttribute( this.attributeName ) );
47
+
48
+ if ( value === this._defaultValue ) {
49
+ return;
50
+ }
51
+
52
+ return value;
46
53
  }
47
54
  }
@@ -37,9 +37,10 @@ export default class TableCellBorderWidthCommand extends TableCellPropertyComman
37
37
  * Creates a new `TableCellBorderWidthCommand` instance.
38
38
  *
39
39
  * @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
40
+ * @param {String} defaultValue The default value of the attribute.
40
41
  */
41
- constructor( editor ) {
42
- super( editor, 'borderWidth' );
42
+ constructor( editor, defaultValue ) {
43
+ super( editor, 'borderWidth', defaultValue );
43
44
  }
44
45
 
45
46
  /**
@@ -50,13 +51,25 @@ export default class TableCellBorderWidthCommand extends TableCellPropertyComman
50
51
  return;
51
52
  }
52
53
 
53
- return getSingleValue( tableCell.getAttribute( this.attributeName ) );
54
+ const value = getSingleValue( tableCell.getAttribute( this.attributeName ) );
55
+
56
+ if ( value === this._defaultValue ) {
57
+ return;
58
+ }
59
+
60
+ return value;
54
61
  }
55
62
 
56
63
  /**
57
64
  * @inheritDoc
58
65
  */
59
66
  _getValueToSet( value ) {
60
- return addDefaultUnitToNumericValue( value, 'px' );
67
+ value = addDefaultUnitToNumericValue( value, 'px' );
68
+
69
+ if ( value === this._defaultValue ) {
70
+ return;
71
+ }
72
+
73
+ return value;
61
74
  }
62
75
  }
@@ -37,15 +37,22 @@ export default class TableCellHeightCommand extends TableCellPropertyCommand {
37
37
  * Creates a new `TableCellHeightCommand` instance.
38
38
  *
39
39
  * @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
40
+ * @param {String} defaultValue The default value of the attribute.
40
41
  */
41
- constructor( editor ) {
42
- super( editor, 'height' );
42
+ constructor( editor, defaultValue ) {
43
+ super( editor, 'height', defaultValue );
43
44
  }
44
45
 
45
46
  /**
46
47
  * @inheritDoc
47
48
  */
48
49
  _getValueToSet( value ) {
49
- return addDefaultUnitToNumericValue( value, 'px' );
50
+ value = addDefaultUnitToNumericValue( value, 'px' );
51
+
52
+ if ( value === this._defaultValue ) {
53
+ return null;
54
+ }
55
+
56
+ return value;
50
57
  }
51
58
  }
@@ -28,8 +28,9 @@ export default class TableCellHorizontalAlignmentCommand extends TableCellProper
28
28
  * Creates a new `TableCellHorizontalAlignmentCommand` instance.
29
29
  *
30
30
  * @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
31
+ * @param {String} defaultValue The default value for the "alignment" attribute.
31
32
  */
32
- constructor( editor ) {
33
- super( editor, 'horizontalAlignment' );
33
+ constructor( editor, defaultValue ) {
34
+ super( editor, 'horizontalAlignment', defaultValue );
34
35
  }
35
36
  }
@@ -37,9 +37,10 @@ export default class TableCellPaddingCommand extends TableCellPropertyCommand {
37
37
  * Creates a new `TableCellPaddingCommand` instance.
38
38
  *
39
39
  * @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
40
+ * @param {String} defaultValue The default value of the attribute.
40
41
  */
41
- constructor( editor ) {
42
- super( editor, 'padding' );
42
+ constructor( editor, defaultValue ) {
43
+ super( editor, 'padding', defaultValue );
43
44
  }
44
45
 
45
46
  /**
@@ -50,13 +51,25 @@ export default class TableCellPaddingCommand extends TableCellPropertyCommand {
50
51
  return;
51
52
  }
52
53
 
53
- return getSingleValue( tableCell.getAttribute( this.attributeName ) );
54
+ const value = getSingleValue( tableCell.getAttribute( this.attributeName ) );
55
+
56
+ if ( value === this._defaultValue ) {
57
+ return;
58
+ }
59
+
60
+ return value;
54
61
  }
55
62
 
56
63
  /**
57
64
  * @inheritDoc
58
65
  */
59
66
  _getValueToSet( value ) {
60
- return addDefaultUnitToNumericValue( value, 'px' );
67
+ value = addDefaultUnitToNumericValue( value, 'px' );
68
+
69
+ if ( value === this._defaultValue ) {
70
+ return;
71
+ }
72
+
73
+ return value;
61
74
  }
62
75
  }
@@ -23,11 +23,27 @@ export default class TableCellPropertyCommand extends Command {
23
23
  *
24
24
  * @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
25
25
  * @param {String} attributeName Table cell attribute name.
26
+ * @param {String} defaultValue The default value of the attribute.
26
27
  */
27
- constructor( editor, attributeName ) {
28
+ constructor( editor, attributeName, defaultValue ) {
28
29
  super( editor );
29
30
 
31
+ /**
32
+ * The attribute that will be set by the command.
33
+ *
34
+ * @readonly
35
+ * @member {String}
36
+ */
30
37
  this.attributeName = attributeName;
38
+
39
+ /**
40
+ * The default value for the attribute.
41
+ *
42
+ * @readonly
43
+ * @protected
44
+ * @member {String}
45
+ */
46
+ this._defaultValue = defaultValue;
31
47
  }
32
48
 
33
49
  /**
@@ -78,7 +94,13 @@ export default class TableCellPropertyCommand extends Command {
78
94
  return;
79
95
  }
80
96
 
81
- return tableCell.getAttribute( this.attributeName );
97
+ const value = tableCell.getAttribute( this.attributeName );
98
+
99
+ if ( value === this._defaultValue ) {
100
+ return;
101
+ }
102
+
103
+ return value;
82
104
  }
83
105
 
84
106
  /**
@@ -89,6 +111,10 @@ export default class TableCellPropertyCommand extends Command {
89
111
  * @returns {*}
90
112
  */
91
113
  _getValueToSet( value ) {
114
+ if ( value === this._defaultValue ) {
115
+ return;
116
+ }
117
+
92
118
  return value;
93
119
  }
94
120
 
@@ -36,8 +36,9 @@ export default class TableCellVerticalAlignmentCommand extends TableCellProperty
36
36
  * Creates a new `TableCellVerticalAlignmentCommand` instance.
37
37
  *
38
38
  * @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
39
+ * @param {String} defaultValue The default value for the "alignment" attribute.
39
40
  */
40
- constructor( editor ) {
41
- super( editor, 'verticalAlignment' );
41
+ constructor( editor, defaultValue ) {
42
+ super( editor, 'verticalAlignment', defaultValue );
42
43
  }
43
44
  }
@@ -37,15 +37,22 @@ export default class TableCellWidthCommand extends TableCellPropertyCommand {
37
37
  * Creates a new `TableCellWidthCommand` instance.
38
38
  *
39
39
  * @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
40
+ * @param {String} defaultValue The default value of the attribute.
40
41
  */
41
- constructor( editor ) {
42
- super( editor, 'width' );
42
+ constructor( editor, defaultValue ) {
43
+ super( editor, 'width', defaultValue );
43
44
  }
44
45
 
45
46
  /**
46
47
  * @inheritDoc
47
48
  */
48
49
  _getValueToSet( value ) {
49
- return addDefaultUnitToNumericValue( value, 'px' );
50
+ value = addDefaultUnitToNumericValue( value, 'px' );
51
+
52
+ if ( value === this._defaultValue ) {
53
+ return;
54
+ }
55
+
56
+ return value;
50
57
  }
51
58
  }
@@ -21,8 +21,10 @@ import TableCellHorizontalAlignmentCommand from './commands/tablecellhorizontala
21
21
  import TableCellBorderStyleCommand from './commands/tablecellborderstylecommand';
22
22
  import TableCellBorderColorCommand from './commands/tablecellbordercolorcommand';
23
23
  import TableCellBorderWidthCommand from './commands/tablecellborderwidthcommand';
24
+ import { getNormalizedDefaultProperties } from '../utils/table-properties';
24
25
 
25
- const VALIGN_VALUES_REG_EXP = /^(top|bottom)$/;
26
+ const VALIGN_VALUES_REG_EXP = /^(top|middle|bottom)$/;
27
+ const ALIGN_VALUES_REG_EXP = /^(left|center|right|justify)$/;
26
28
 
27
29
  /**
28
30
  * The table cell properties editing feature.
@@ -67,33 +69,74 @@ export default class TableCellPropertiesEditing extends Plugin {
67
69
  const editor = this.editor;
68
70
  const schema = editor.model.schema;
69
71
  const conversion = editor.conversion;
70
- const locale = editor.locale;
72
+
73
+ editor.config.define( 'table.tableCellProperties.defaultProperties', {} );
74
+
75
+ const defaultTableCellProperties = getNormalizedDefaultProperties(
76
+ editor.config.get( 'table.tableCellProperties.defaultProperties' ),
77
+ {
78
+ includeVerticalAlignmentProperty: true,
79
+ includeHorizontalAlignmentProperty: true,
80
+ includePaddingProperty: true,
81
+ isRightToLeftContent: editor.locale.contentLanguageDirection === 'rtl'
82
+ }
83
+ );
71
84
 
72
85
  editor.data.addStyleProcessorRules( addBorderRules );
73
- enableBorderProperties( schema, conversion );
74
- editor.commands.add( 'tableCellBorderStyle', new TableCellBorderStyleCommand( editor ) );
75
- editor.commands.add( 'tableCellBorderColor', new TableCellBorderColorCommand( editor ) );
76
- editor.commands.add( 'tableCellBorderWidth', new TableCellBorderWidthCommand( editor ) );
86
+ enableBorderProperties( schema, conversion, {
87
+ color: defaultTableCellProperties.borderColor,
88
+ style: defaultTableCellProperties.borderStyle,
89
+ width: defaultTableCellProperties.borderWidth
90
+ } );
91
+ editor.commands.add( 'tableCellBorderStyle', new TableCellBorderStyleCommand( editor, defaultTableCellProperties.borderStyle ) );
92
+ editor.commands.add( 'tableCellBorderColor', new TableCellBorderColorCommand( editor, defaultTableCellProperties.borderColor ) );
93
+ editor.commands.add( 'tableCellBorderWidth', new TableCellBorderWidthCommand( editor, defaultTableCellProperties.borderWidth ) );
77
94
 
78
- enableHorizontalAlignmentProperty( schema, conversion, locale );
79
- editor.commands.add( 'tableCellHorizontalAlignment', new TableCellHorizontalAlignmentCommand( editor ) );
95
+ enableHorizontalAlignmentProperty( schema, conversion, defaultTableCellProperties.horizontalAlignment );
96
+ editor.commands.add(
97
+ 'tableCellHorizontalAlignment',
98
+ new TableCellHorizontalAlignmentCommand( editor, defaultTableCellProperties.horizontalAlignment )
99
+ );
80
100
 
81
- enableProperty( schema, conversion, 'width', 'width' );
82
- editor.commands.add( 'tableCellWidth', new TableCellWidthCommand( editor ) );
101
+ enableProperty( schema, conversion, {
102
+ modelAttribute: 'width',
103
+ styleName: 'width',
104
+ defaultValue: defaultTableCellProperties.width
105
+ } );
106
+ editor.commands.add( 'tableCellWidth', new TableCellWidthCommand( editor, defaultTableCellProperties.width ) );
83
107
 
84
- enableProperty( schema, conversion, 'height', 'height' );
85
- editor.commands.add( 'tableCellHeight', new TableCellHeightCommand( editor ) );
108
+ enableProperty( schema, conversion, {
109
+ modelAttribute: 'height',
110
+ styleName: 'height',
111
+ defaultValue: defaultTableCellProperties.height
112
+ } );
113
+ editor.commands.add( 'tableCellHeight', new TableCellHeightCommand( editor, defaultTableCellProperties.height ) );
86
114
 
87
115
  editor.data.addStyleProcessorRules( addPaddingRules );
88
- enableProperty( schema, conversion, 'padding', 'padding' );
89
- editor.commands.add( 'tableCellPadding', new TableCellPaddingCommand( editor ) );
116
+ enableProperty( schema, conversion, {
117
+ modelAttribute: 'padding',
118
+ styleName: 'padding',
119
+ reduceBoxSides: true,
120
+ defaultValue: defaultTableCellProperties.padding
121
+ } );
122
+ editor.commands.add( 'tableCellPadding', new TableCellPaddingCommand( editor, defaultTableCellProperties.padding ) );
90
123
 
91
124
  editor.data.addStyleProcessorRules( addBackgroundRules );
92
- enableProperty( schema, conversion, 'backgroundColor', 'background-color' );
93
- editor.commands.add( 'tableCellBackgroundColor', new TableCellBackgroundColorCommand( editor ) );
125
+ enableProperty( schema, conversion, {
126
+ modelAttribute: 'backgroundColor',
127
+ styleName: 'background-color',
128
+ defaultValue: defaultTableCellProperties.backgroundColor
129
+ } );
130
+ editor.commands.add(
131
+ 'tableCellBackgroundColor',
132
+ new TableCellBackgroundColorCommand( editor, defaultTableCellProperties.backgroundColor )
133
+ );
94
134
 
95
- enableVerticalAlignmentProperty( schema, conversion );
96
- editor.commands.add( 'tableCellVerticalAlignment', new TableCellVerticalAlignmentCommand( editor ) );
135
+ enableVerticalAlignmentProperty( schema, conversion, defaultTableCellProperties.verticalAlignment );
136
+ editor.commands.add(
137
+ 'tableCellVerticalAlignment',
138
+ new TableCellVerticalAlignmentCommand( editor, defaultTableCellProperties.verticalAlignment )
139
+ );
97
140
  }
98
141
  }
99
142
 
@@ -101,15 +144,19 @@ export default class TableCellPropertiesEditing extends Plugin {
101
144
  //
102
145
  // @param {module:engine/model/schema~Schema} schema
103
146
  // @param {module:engine/conversion/conversion~Conversion} conversion
104
- function enableBorderProperties( schema, conversion ) {
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.
151
+ function enableBorderProperties( schema, conversion, defaultBorder ) {
105
152
  schema.extend( 'tableCell', {
106
153
  allowAttributes: [ 'borderWidth', 'borderColor', 'borderStyle' ]
107
154
  } );
108
- upcastBorderStyles( conversion, 'td' );
109
- upcastBorderStyles( conversion, 'th' );
110
- downcastAttributeToStyle( conversion, 'tableCell', 'borderStyle', 'border-style' );
111
- downcastAttributeToStyle( conversion, 'tableCell', 'borderColor', 'border-color' );
112
- downcastAttributeToStyle( conversion, 'tableCell', 'borderWidth', 'border-width' );
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' } );
113
160
  }
114
161
 
115
162
  // Enables the `'horizontalAlignment'` attribute for table cells.
@@ -117,88 +164,140 @@ function enableBorderProperties( schema, conversion ) {
117
164
  // @param {module:engine/model/schema~Schema} schema
118
165
  // @param {module:engine/conversion/conversion~Conversion} conversion
119
166
  // @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
120
- function enableHorizontalAlignmentProperty( schema, conversion, locale ) {
167
+ // @param {String} defaultValue The default horizontal alignment value.
168
+ function enableHorizontalAlignmentProperty( schema, conversion, defaultValue ) {
121
169
  schema.extend( 'tableCell', {
122
170
  allowAttributes: [ 'horizontalAlignment' ]
123
171
  } );
124
172
 
125
- const options = [ locale.contentLanguageDirection == 'rtl' ? 'left' : 'right', 'center', 'justify' ];
126
-
127
- conversion.attributeToAttribute( {
128
- model: {
129
- name: 'tableCell',
130
- key: 'horizontalAlignment',
131
- values: options
132
- },
133
- view: options.reduce( ( result, option ) => ( {
134
- ...result,
135
- [ option ]: {
173
+ conversion.for( 'downcast' )
174
+ .attributeToAttribute( {
175
+ model: {
176
+ name: 'tableCell',
177
+ key: 'horizontalAlignment'
178
+ },
179
+ view: alignment => ( {
136
180
  key: 'style',
137
181
  value: {
138
- 'text-align': option
182
+ 'text-align': alignment
183
+ }
184
+ } )
185
+ } );
186
+
187
+ conversion.for( 'upcast' )
188
+ // Support for the `text-align:*;` CSS definition for the table cell alignment.
189
+ .attributeToAttribute( {
190
+ view: {
191
+ name: /^(td|th)$/,
192
+ styles: {
193
+ 'text-align': ALIGN_VALUES_REG_EXP
194
+ }
195
+ },
196
+ model: {
197
+ key: 'horizontalAlignment',
198
+ value: viewElement => {
199
+ const align = viewElement.getStyle( 'text-align' );
200
+
201
+ return align === defaultValue ? null : align;
139
202
  }
140
203
  }
141
- } ), {} )
142
- } );
204
+ } )
205
+ // Support for the `align` attribute as the backward compatibility while pasting from other sources.
206
+ .attributeToAttribute( {
207
+ view: {
208
+ name: /^(td|th)$/,
209
+ attributes: {
210
+ align: ALIGN_VALUES_REG_EXP
211
+ }
212
+ },
213
+ model: {
214
+ key: 'horizontalAlignment',
215
+ value: viewElement => {
216
+ const align = viewElement.getAttribute( 'align' );
217
+
218
+ return align === defaultValue ? null : align;
219
+ }
220
+ }
221
+ } );
143
222
  }
144
223
 
145
224
  // Enables the `'verticalAlignment'` attribute for table cells.
146
225
  //
147
226
  // @param {module:engine/model/schema~Schema} schema
148
227
  // @param {module:engine/conversion/conversion~Conversion} conversion
149
- function enableVerticalAlignmentProperty( schema, conversion ) {
228
+ // @param {String} defaultValue The default vertical alignment value.
229
+ function enableVerticalAlignmentProperty( schema, conversion, defaultValue ) {
150
230
  schema.extend( 'tableCell', {
151
231
  allowAttributes: [ 'verticalAlignment' ]
152
232
  } );
153
233
 
154
- conversion.attributeToAttribute( {
155
- model: {
156
- name: 'tableCell',
157
- key: 'verticalAlignment',
158
- values: [ 'top', 'bottom' ]
159
- },
160
- view: {
161
- top: {
162
- key: 'style',
163
- value: {
164
- 'vertical-align': 'top'
165
- }
234
+ conversion.for( 'downcast' )
235
+ .attributeToAttribute( {
236
+ model: {
237
+ name: 'tableCell',
238
+ key: 'verticalAlignment'
166
239
  },
167
- bottom: {
240
+ view: alignment => ( {
168
241
  key: 'style',
169
242
  value: {
170
- 'vertical-align': 'bottom'
243
+ 'vertical-align': alignment
171
244
  }
172
- }
173
- }
174
- } );
245
+ } )
246
+ } );
175
247
 
176
248
  conversion.for( 'upcast' )
177
- // Support for backwards compatibility and pasting from other sources.
249
+ // Support for the `vertical-align:*;` CSS definition for the table cell alignment.
178
250
  .attributeToAttribute( {
179
251
  view: {
252
+ name: /^(td|th)$/,
253
+ styles: {
254
+ 'vertical-align': VALIGN_VALUES_REG_EXP
255
+ }
256
+ },
257
+ model: {
258
+ key: 'verticalAlignment',
259
+ value: viewElement => {
260
+ const align = viewElement.getStyle( 'vertical-align' );
261
+
262
+ return align === defaultValue ? null : align;
263
+ }
264
+ }
265
+ } )
266
+ // Support for the `align` attribute as the backward compatibility while pasting from other sources.
267
+ .attributeToAttribute( {
268
+ view: {
269
+ name: /^(td|th)$/,
180
270
  attributes: {
181
271
  valign: VALIGN_VALUES_REG_EXP
182
272
  }
183
273
  },
184
274
  model: {
185
- name: 'tableCell',
186
275
  key: 'verticalAlignment',
187
- value: viewElement => viewElement.getAttribute( 'valign' )
276
+ value: viewElement => {
277
+ const valign = viewElement.getAttribute( 'valign' );
278
+
279
+ return valign === defaultValue ? null : valign;
280
+ }
188
281
  }
189
282
  } );
190
283
  }
191
284
 
192
285
  // Enables conversion for an attribute for simple view-model mappings.
193
286
  //
194
- // @param {String} modelAttribute
195
- // @param {String} styleName
196
287
  // @param {module:engine/model/schema~Schema} schema
197
288
  // @param {module:engine/conversion/conversion~Conversion} conversion
198
- function enableProperty( schema, conversion, modelAttribute, styleName ) {
289
+ // @param {Object} options
290
+ // @param {String} options.modelAttribute
291
+ // @param {String} options.styleName
292
+ // @param {String} options.defaultValue The default value for the specified `modelAttribute`.
293
+ // @param {Boolean} [options.reduceBoxSides=false]
294
+ function enableProperty( schema, conversion, options ) {
295
+ const { modelAttribute } = options;
296
+
199
297
  schema.extend( 'tableCell', {
200
298
  allowAttributes: [ modelAttribute ]
201
299
  } );
202
- upcastStyleToAttribute( conversion, 'tableCell', modelAttribute, styleName );
203
- downcastAttributeToStyle( conversion, 'tableCell', modelAttribute, styleName );
300
+
301
+ upcastStyleToAttribute( conversion, { viewElement: /^(td|th)$/, ...options } );
302
+ downcastAttributeToStyle( conversion, { modelElement: 'tableCell', ...options } );
204
303
  }