@ckeditor/ckeditor5-table 36.0.0 → 37.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/build/table.js +1 -1
  2. package/package.json +34 -29
  3. package/src/commands/insertcolumncommand.d.ts +61 -0
  4. package/src/commands/insertcolumncommand.js +45 -60
  5. package/src/commands/insertrowcommand.d.ts +60 -0
  6. package/src/commands/insertrowcommand.js +44 -59
  7. package/src/commands/inserttablecommand.d.ts +50 -0
  8. package/src/commands/inserttablecommand.js +51 -68
  9. package/src/commands/mergecellcommand.d.ts +76 -0
  10. package/src/commands/mergecellcommand.js +169 -244
  11. package/src/commands/mergecellscommand.d.ts +33 -0
  12. package/src/commands/mergecellscommand.js +72 -101
  13. package/src/commands/removecolumncommand.d.ts +34 -0
  14. package/src/commands/removecolumncommand.js +88 -102
  15. package/src/commands/removerowcommand.d.ts +34 -0
  16. package/src/commands/removerowcommand.js +63 -80
  17. package/src/commands/selectcolumncommand.d.ts +38 -0
  18. package/src/commands/selectcolumncommand.js +41 -54
  19. package/src/commands/selectrowcommand.d.ts +38 -0
  20. package/src/commands/selectrowcommand.js +38 -48
  21. package/src/commands/setheadercolumncommand.d.ts +55 -0
  22. package/src/commands/setheadercolumncommand.js +48 -73
  23. package/src/commands/setheaderrowcommand.d.ts +58 -0
  24. package/src/commands/setheaderrowcommand.js +56 -85
  25. package/src/commands/splitcellcommand.d.ts +49 -0
  26. package/src/commands/splitcellcommand.js +35 -49
  27. package/src/converters/downcast.d.ts +63 -0
  28. package/src/converters/downcast.js +98 -130
  29. package/src/converters/table-caption-post-fixer.d.ts +20 -0
  30. package/src/converters/table-caption-post-fixer.js +36 -52
  31. package/src/converters/table-cell-paragraph-post-fixer.d.ts +32 -0
  32. package/src/converters/table-cell-paragraph-post-fixer.js +88 -119
  33. package/src/converters/table-cell-refresh-handler.d.ts +18 -0
  34. package/src/converters/table-cell-refresh-handler.js +29 -48
  35. package/src/converters/table-headings-refresh-handler.d.ts +17 -0
  36. package/src/converters/table-headings-refresh-handler.js +35 -54
  37. package/src/converters/table-layout-post-fixer.d.ts +226 -0
  38. package/src/converters/table-layout-post-fixer.js +276 -313
  39. package/src/converters/tableproperties.d.ts +54 -0
  40. package/src/converters/tableproperties.js +136 -168
  41. package/src/converters/upcasttable.d.ts +49 -0
  42. package/src/converters/upcasttable.js +196 -251
  43. package/src/index.d.ts +29 -0
  44. package/src/index.js +0 -2
  45. package/src/plaintableoutput.d.ts +30 -0
  46. package/src/plaintableoutput.js +107 -135
  47. package/src/table.d.ts +38 -0
  48. package/src/table.js +12 -88
  49. package/src/tablecaption/tablecaptionediting.d.ts +68 -0
  50. package/src/tablecaption/tablecaptionediting.js +104 -135
  51. package/src/tablecaption/tablecaptionui.d.ts +26 -0
  52. package/src/tablecaption/tablecaptionui.js +42 -58
  53. package/src/tablecaption/toggletablecaptioncommand.d.ts +73 -0
  54. package/src/tablecaption/toggletablecaptioncommand.js +77 -92
  55. package/src/tablecaption/utils.d.ts +42 -0
  56. package/src/tablecaption/utils.js +35 -61
  57. package/src/tablecaption.d.ts +27 -0
  58. package/src/tablecaption.js +12 -19
  59. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.d.ts +37 -0
  60. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +14 -20
  61. package/src/tablecellproperties/commands/tablecellbordercolorcommand.d.ts +42 -0
  62. package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +27 -37
  63. package/src/tablecellproperties/commands/tablecellborderstylecommand.d.ts +42 -0
  64. package/src/tablecellproperties/commands/tablecellborderstylecommand.js +27 -37
  65. package/src/tablecellproperties/commands/tablecellborderwidthcommand.d.ts +56 -0
  66. package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +42 -53
  67. package/src/tablecellproperties/commands/tablecellheightcommand.d.ts +51 -0
  68. package/src/tablecellproperties/commands/tablecellheightcommand.js +29 -36
  69. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.d.ts +37 -0
  70. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +14 -20
  71. package/src/tablecellproperties/commands/tablecellpaddingcommand.d.ts +56 -0
  72. package/src/tablecellproperties/commands/tablecellpaddingcommand.js +42 -53
  73. package/src/tablecellproperties/commands/tablecellpropertycommand.d.ts +62 -0
  74. package/src/tablecellproperties/commands/tablecellpropertycommand.js +77 -122
  75. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.d.ts +45 -0
  76. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +14 -20
  77. package/src/tablecellproperties/tablecellpropertiesediting.d.ts +47 -0
  78. package/src/tablecellproperties/tablecellpropertiesediting.js +194 -236
  79. package/src/tablecellproperties/tablecellpropertiesui.d.ts +117 -0
  80. package/src/tablecellproperties/tablecellpropertiesui.js +303 -456
  81. package/src/tablecellproperties/ui/tablecellpropertiesview.d.ts +227 -0
  82. package/src/tablecellproperties/ui/tablecellpropertiesview.js +509 -844
  83. package/src/tablecellproperties.d.ts +33 -0
  84. package/src/tablecellproperties.js +12 -98
  85. package/src/tablecellwidth/commands/tablecellwidthcommand.d.ts +51 -0
  86. package/src/tablecellwidth/commands/tablecellwidthcommand.js +29 -35
  87. package/src/tablecellwidth/tablecellwidthediting.d.ts +34 -0
  88. package/src/tablecellwidth/tablecellwidthediting.js +26 -38
  89. package/src/tableclipboard.d.ts +68 -0
  90. package/src/tableclipboard.js +429 -568
  91. package/src/tablecolumnresize/constants.d.ts +20 -0
  92. package/src/tablecolumnresize/constants.js +0 -10
  93. package/src/tablecolumnresize/converters.d.ts +18 -0
  94. package/src/tablecolumnresize/converters.js +35 -119
  95. package/src/tablecolumnresize/tablecolumnresizeediting.d.ts +142 -0
  96. package/src/tablecolumnresize/tablecolumnresizeediting.js +545 -711
  97. package/src/tablecolumnresize/tablewidthscommand.d.ts +38 -0
  98. package/src/tablecolumnresize/tablewidthscommand.js +61 -0
  99. package/src/tablecolumnresize/utils.d.ts +141 -0
  100. package/src/tablecolumnresize/utils.js +256 -233
  101. package/src/tablecolumnresize.d.ts +29 -0
  102. package/src/tablecolumnresize.js +12 -19
  103. package/src/tableconfig.d.ts +341 -0
  104. package/src/tableconfig.js +5 -0
  105. package/src/tableediting.d.ts +102 -0
  106. package/src/tableediting.js +157 -176
  107. package/src/tablekeyboard.d.ts +68 -0
  108. package/src/tablekeyboard.js +261 -344
  109. package/src/tablemouse/mouseeventsobserver.d.ts +62 -0
  110. package/src/tablemouse/mouseeventsobserver.js +12 -49
  111. package/src/tablemouse.d.ts +51 -0
  112. package/src/tablemouse.js +154 -202
  113. package/src/tableproperties/commands/tablealignmentcommand.d.ts +37 -0
  114. package/src/tableproperties/commands/tablealignmentcommand.js +14 -20
  115. package/src/tableproperties/commands/tablebackgroundcolorcommand.d.ts +37 -0
  116. package/src/tableproperties/commands/tablebackgroundcolorcommand.js +14 -20
  117. package/src/tableproperties/commands/tablebordercolorcommand.d.ts +42 -0
  118. package/src/tableproperties/commands/tablebordercolorcommand.js +27 -37
  119. package/src/tableproperties/commands/tableborderstylecommand.d.ts +42 -0
  120. package/src/tableproperties/commands/tableborderstylecommand.js +27 -37
  121. package/src/tableproperties/commands/tableborderwidthcommand.d.ts +56 -0
  122. package/src/tableproperties/commands/tableborderwidthcommand.js +42 -53
  123. package/src/tableproperties/commands/tableheightcommand.d.ts +51 -0
  124. package/src/tableproperties/commands/tableheightcommand.js +29 -33
  125. package/src/tableproperties/commands/tablepropertycommand.d.ts +61 -0
  126. package/src/tableproperties/commands/tablepropertycommand.js +68 -112
  127. package/src/tableproperties/commands/tablewidthcommand.d.ts +51 -0
  128. package/src/tableproperties/commands/tablewidthcommand.js +29 -33
  129. package/src/tableproperties/tablepropertiesediting.d.ts +45 -0
  130. package/src/tableproperties/tablepropertiesediting.js +164 -210
  131. package/src/tableproperties/tablepropertiesui.d.ts +119 -0
  132. package/src/tableproperties/tablepropertiesui.js +294 -439
  133. package/src/tableproperties/ui/tablepropertiesview.d.ts +203 -0
  134. package/src/tableproperties/ui/tablepropertiesview.js +427 -718
  135. package/src/tableproperties.d.ts +33 -0
  136. package/src/tableproperties.js +12 -95
  137. package/src/tableselection.d.ts +111 -0
  138. package/src/tableselection.js +279 -376
  139. package/src/tabletoolbar.d.ts +37 -0
  140. package/src/tabletoolbar.js +39 -92
  141. package/src/tableui.d.ts +58 -0
  142. package/src/tableui.js +281 -338
  143. package/src/tableutils.d.ts +453 -0
  144. package/src/tableutils.js +1015 -1229
  145. package/src/tablewalker.d.ts +323 -0
  146. package/src/tablewalker.js +308 -548
  147. package/src/ui/colorinputview.d.ts +143 -0
  148. package/src/ui/colorinputview.js +229 -366
  149. package/src/ui/formrowview.d.ts +61 -0
  150. package/src/ui/formrowview.js +38 -84
  151. package/src/ui/inserttableview.d.ts +77 -0
  152. package/src/ui/inserttableview.js +152 -242
  153. package/src/utils/common.d.ts +42 -0
  154. package/src/utils/common.js +33 -57
  155. package/src/utils/structure.d.ts +245 -0
  156. package/src/utils/structure.js +261 -379
  157. package/src/utils/table-properties.d.ts +67 -0
  158. package/src/utils/table-properties.js +60 -81
  159. package/src/utils/ui/contextualballoon.d.ts +34 -0
  160. package/src/utils/ui/contextualballoon.js +70 -89
  161. package/src/utils/ui/table-properties.d.ts +193 -0
  162. package/src/utils/ui/table-properties.js +259 -319
  163. package/src/utils/ui/widget.d.ts +16 -0
  164. package/src/utils/ui/widget.js +24 -46
  165. package/src/tablecolumnresize/tablecolumnwidthscommand.js +0 -55
  166. package/src/tablecolumnresize/tablewidthresizecommand.js +0 -65
@@ -2,865 +2,530 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module table/tablecellproperties/ui/tablecellpropertiesview
8
7
  */
9
-
10
- import {
11
- LabeledFieldView,
12
- createLabeledDropdown,
13
- createLabeledInputText,
14
- LabelView,
15
- addListToDropdown,
16
- ToolbarView,
17
- ButtonView,
18
- FocusCycler,
19
- View,
20
- ViewCollection,
21
- FormHeaderView,
22
- submitHandler
23
- } from 'ckeditor5/src/ui';
8
+ import { addListToDropdown, ButtonView, createLabeledDropdown, createLabeledInputText, FocusCycler, FormHeaderView, LabeledFieldView, LabelView, submitHandler, ToolbarView, View, ViewCollection } from 'ckeditor5/src/ui';
24
9
  import { KeystrokeHandler, FocusTracker } from 'ckeditor5/src/utils';
25
10
  import { icons } from 'ckeditor5/src/core';
26
-
27
- import {
28
- fillToolbar,
29
- getBorderStyleDefinitions,
30
- getBorderStyleLabels,
31
- getLabeledColorInputCreator
32
- } from '../../utils/ui/table-properties';
11
+ import { fillToolbar, getBorderStyleDefinitions, getBorderStyleLabels, getLabeledColorInputCreator } from '../../utils/ui/table-properties';
33
12
  import FormRowView from '../../ui/formrowview';
34
-
35
13
  import '../../../theme/form.css';
36
14
  import '../../../theme/tableform.css';
37
15
  import '../../../theme/tablecellproperties.css';
38
-
39
16
  const ALIGNMENT_ICONS = {
40
- left: icons.alignLeft,
41
- center: icons.alignCenter,
42
- right: icons.alignRight,
43
- justify: icons.alignJustify,
44
- top: icons.alignTop,
45
- middle: icons.alignMiddle,
46
- bottom: icons.alignBottom
17
+ left: icons.alignLeft,
18
+ center: icons.alignCenter,
19
+ right: icons.alignRight,
20
+ justify: icons.alignJustify,
21
+ top: icons.alignTop,
22
+ middle: icons.alignMiddle,
23
+ bottom: icons.alignBottom
47
24
  };
48
-
49
25
  /**
50
26
  * The class representing a table cell properties form, allowing users to customize
51
27
  * certain style aspects of a table cell, for instance, border, padding, text alignment, etc..
52
- *
53
- * @extends module:ui/view~View
54
28
  */
55
29
  export default class TableCellPropertiesView extends View {
56
- /**
57
- * @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
58
- * @param {Object} options Additional configuration of the view.
59
- * @param {module:table/table~TableColorConfig} options.borderColors A configuration of the border
60
- * color palette used by the
61
- * {@link module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView#borderColorInput}.
62
- * @param {module:table/table~TableColorConfig} options.backgroundColors A configuration of the background
63
- * color palette used by the
64
- * {@link module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView#backgroundInput}.
65
- * @param {module:table/tablecellproperties~TableCellPropertiesOptions} options.defaultTableCellProperties The default
66
- * table cell properties.
67
- */
68
- constructor( locale, options ) {
69
- super( locale );
70
-
71
- this.set( {
72
- /**
73
- * The value of the cell border style.
74
- *
75
- * @observable
76
- * @default ''
77
- * @member #borderStyle
78
- */
79
- borderStyle: '',
80
-
81
- /**
82
- * The value of the cell border width style.
83
- *
84
- * @observable
85
- * @default ''
86
- * @member #borderWidth
87
- */
88
- borderWidth: '',
89
-
90
- /**
91
- * The value of the cell border color style.
92
- *
93
- * @observable
94
- * @default ''
95
- * @member #borderColor
96
- */
97
- borderColor: '',
98
-
99
- /**
100
- * The value of the cell padding style.
101
- *
102
- * @observable
103
- * @default ''
104
- * @member #padding
105
- */
106
- padding: '',
107
-
108
- /**
109
- * The value of the cell background color style.
110
- *
111
- * @observable
112
- * @default ''
113
- * @member #backgroundColor
114
- */
115
- backgroundColor: '',
116
-
117
- /**
118
- * The value of the table cell width style.
119
- *
120
- * @observable
121
- * @default ''
122
- * @member #width
123
- */
124
- width: '',
125
-
126
- /**
127
- * The value of the table cell height style.
128
- *
129
- * @observable
130
- * @default ''
131
- * @member #height
132
- */
133
- height: '',
134
-
135
- /**
136
- * The value of the horizontal text alignment style.
137
- *
138
- * @observable
139
- * @default ''
140
- * @member #horizontalAlignment
141
- */
142
- horizontalAlignment: '',
143
-
144
- /**
145
- * The value of the vertical text alignment style.
146
- *
147
- * @observable
148
- * @default ''
149
- * @member #verticalAlignment
150
- */
151
- verticalAlignment: ''
152
- } );
153
-
154
- /**
155
- * Options passed to the view. See {@link #constructor} to learn more.
156
- *
157
- * @member {Object}
158
- */
159
- this.options = options;
160
-
161
- const { borderStyleDropdown, borderWidthInput, borderColorInput, borderRowLabel } = this._createBorderFields();
162
- const { backgroundRowLabel, backgroundInput } = this._createBackgroundFields();
163
- const { widthInput, operatorLabel, heightInput, dimensionsLabel } = this._createDimensionFields();
164
- const { horizontalAlignmentToolbar, verticalAlignmentToolbar, alignmentLabel } = this._createAlignmentFields();
165
-
166
- /**
167
- * Tracks information about the DOM focus in the form.
168
- *
169
- * @readonly
170
- * @member {module:utils/focustracker~FocusTracker}
171
- */
172
- this.focusTracker = new FocusTracker();
173
-
174
- /**
175
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
176
- *
177
- * @readonly
178
- * @member {module:utils/keystrokehandler~KeystrokeHandler}
179
- */
180
- this.keystrokes = new KeystrokeHandler();
181
-
182
- /**
183
- * A collection of child views in the form.
184
- *
185
- * @readonly
186
- * @type {module:ui/viewcollection~ViewCollection}
187
- */
188
- this.children = this.createCollection();
189
-
190
- /**
191
- * A dropdown that allows selecting the style of the table cell border.
192
- *
193
- * @readonly
194
- * @member {module:ui/dropdown/dropdownview~DropdownView}
195
- */
196
- this.borderStyleDropdown = borderStyleDropdown;
197
-
198
- /**
199
- * An input that allows specifying the width of the table cell border.
200
- *
201
- * @readonly
202
- * @member {module:ui/inputtext/inputtextview~InputTextView}
203
- */
204
- this.borderWidthInput = borderWidthInput;
205
-
206
- /**
207
- * An input that allows specifying the color of the table cell border.
208
- *
209
- * @readonly
210
- * @member {module:table/ui/colorinputview~ColorInputView}
211
- */
212
- this.borderColorInput = borderColorInput;
213
-
214
- /**
215
- * An input that allows specifying the table cell background color.
216
- *
217
- * @readonly
218
- * @member {module:table/ui/colorinputview~ColorInputView}
219
- */
220
- this.backgroundInput = backgroundInput;
221
-
222
- /**
223
- * An input that allows specifying the table cell padding.
224
- *
225
- * @readonly
226
- * @member {module:ui/inputtext/inputtextview~InputTextView}
227
- */
228
- this.paddingInput = this._createPaddingField();
229
-
230
- /**
231
- * An input that allows specifying the table cell width.
232
- *
233
- * @readonly
234
- * @member {module:ui/inputtext/inputtextview~InputTextView}
235
- */
236
- this.widthInput = widthInput;
237
-
238
- /**
239
- * An input that allows specifying the table cell height.
240
- *
241
- * @readonly
242
- * @member {module:ui/inputtext/inputtextview~InputTextView}
243
- */
244
- this.heightInput = heightInput;
245
-
246
- /**
247
- * A toolbar with buttons that allow changing the horizontal text alignment in a table cell.
248
- *
249
- * @readonly
250
- * @member {module:ui/toolbar/toolbarview~ToolbarView}
251
- */
252
- this.horizontalAlignmentToolbar = horizontalAlignmentToolbar;
253
-
254
- /**
255
- * A toolbar with buttons that allow changing the vertical text alignment in a table cell.
256
- *
257
- * @readonly
258
- * @member {module:ui/toolbar/toolbarview~ToolbarView}
259
- */
260
- this.verticalAlignmentToolbar = verticalAlignmentToolbar;
261
-
262
- // Defer creating to make sure other fields are present and the Save button can
263
- // bind its #isEnabled to their error messages so there's no way to save unless all
264
- // fields are valid.
265
- const { saveButtonView, cancelButtonView } = this._createActionButtons();
266
-
267
- /**
268
- * The "Save" button view.
269
- *
270
- * @member {module:ui/button/buttonview~ButtonView}
271
- */
272
- this.saveButtonView = saveButtonView;
273
-
274
- /**
275
- * The "Cancel" button view.
276
- *
277
- * @member {module:ui/button/buttonview~ButtonView}
278
- */
279
- this.cancelButtonView = cancelButtonView;
280
-
281
- /**
282
- * A collection of views that can be focused in the form.
283
- *
284
- * @readonly
285
- * @protected
286
- * @member {module:ui/viewcollection~ViewCollection}
287
- */
288
- this._focusables = new ViewCollection();
289
-
290
- /**
291
- * Helps cycling over {@link #_focusables} in the form.
292
- *
293
- * @readonly
294
- * @protected
295
- * @member {module:ui/focuscycler~FocusCycler}
296
- */
297
- this._focusCycler = new FocusCycler( {
298
- focusables: this._focusables,
299
- focusTracker: this.focusTracker,
300
- keystrokeHandler: this.keystrokes,
301
- actions: {
302
- // Navigate form fields backwards using the Shift + Tab keystroke.
303
- focusPrevious: 'shift + tab',
304
-
305
- // Navigate form fields forwards using the Tab key.
306
- focusNext: 'tab'
307
- }
308
- } );
309
-
310
- // Form header.
311
- this.children.add( new FormHeaderView( locale, {
312
- label: this.t( 'Cell properties' )
313
- } ) );
314
-
315
- // Border row.
316
- this.children.add( new FormRowView( locale, {
317
- labelView: borderRowLabel,
318
- children: [
319
- borderRowLabel,
320
- borderStyleDropdown,
321
- borderColorInput,
322
- borderWidthInput
323
- ],
324
- class: 'ck-table-form__border-row'
325
- } ) );
326
-
327
- // Background.
328
- this.children.add( new FormRowView( locale, {
329
- labelView: backgroundRowLabel,
330
- children: [
331
- backgroundRowLabel,
332
- backgroundInput
333
- ],
334
- class: 'ck-table-form__background-row'
335
- } ) );
336
-
337
- // Dimensions row and padding.
338
- this.children.add( new FormRowView( locale, {
339
- children: [
340
- // Dimensions row.
341
- new FormRowView( locale, {
342
- labelView: dimensionsLabel,
343
- children: [
344
- dimensionsLabel,
345
- widthInput,
346
- operatorLabel,
347
- heightInput
348
- ],
349
- class: 'ck-table-form__dimensions-row'
350
- } ),
351
- // Padding row.
352
- new FormRowView( locale, {
353
- children: [
354
- this.paddingInput
355
- ],
356
- class: 'ck-table-cell-properties-form__padding-row'
357
- } )
358
- ]
359
- } ) );
360
-
361
- // Text alignment row.
362
- this.children.add( new FormRowView( locale, {
363
- labelView: alignmentLabel,
364
- children: [
365
- alignmentLabel,
366
- horizontalAlignmentToolbar,
367
- verticalAlignmentToolbar
368
- ],
369
- class: 'ck-table-cell-properties-form__alignment-row'
370
- } ) );
371
-
372
- // Action row.
373
- this.children.add( new FormRowView( locale, {
374
- children: [
375
- this.saveButtonView,
376
- this.cancelButtonView
377
- ],
378
- class: 'ck-table-form__action-row'
379
- } ) );
380
-
381
- this.setTemplate( {
382
- tag: 'form',
383
- attributes: {
384
- class: [
385
- 'ck',
386
- 'ck-form',
387
- 'ck-table-form',
388
- 'ck-table-cell-properties-form'
389
- ],
390
- // https://github.com/ckeditor/ckeditor5-link/issues/90
391
- tabindex: '-1'
392
- },
393
- children: this.children
394
- } );
395
- }
396
-
397
- /**
398
- * @inheritDoc
399
- */
400
- render() {
401
- super.render();
402
-
403
- // Enable the "submit" event for this view. It can be triggered by the #saveButtonView
404
- // which is of the "submit" DOM "type".
405
- submitHandler( {
406
- view: this
407
- } );
408
-
409
- [
410
- this.borderStyleDropdown,
411
- this.borderColorInput,
412
- this.borderColorInput.fieldView.dropdownView.buttonView,
413
- this.borderWidthInput,
414
- this.backgroundInput,
415
- this.backgroundInput.fieldView.dropdownView.buttonView,
416
- this.widthInput,
417
- this.heightInput,
418
- this.paddingInput,
419
- this.horizontalAlignmentToolbar,
420
- this.verticalAlignmentToolbar,
421
- this.saveButtonView,
422
- this.cancelButtonView
423
- ].forEach( view => {
424
- // Register the view as focusable.
425
- this._focusables.add( view );
426
-
427
- // Register the view in the focus tracker.
428
- this.focusTracker.add( view.element );
429
- } );
430
-
431
- // Mainly for closing using "Esc" and navigation using "Tab".
432
- this.keystrokes.listenTo( this.element );
433
- }
434
-
435
- /**
436
- * @inheritDoc
437
- */
438
- destroy() {
439
- super.destroy();
440
-
441
- this.focusTracker.destroy();
442
- this.keystrokes.destroy();
443
- }
444
-
445
- /**
446
- * Focuses the fist focusable field in the form.
447
- */
448
- focus() {
449
- this._focusCycler.focusFirst();
450
- }
451
-
452
- /**
453
- * Creates the following form fields:
454
- *
455
- * * {@link #borderStyleDropdown},
456
- * * {@link #borderWidthInput},
457
- * * {@link #borderColorInput}.
458
- *
459
- * @private
460
- * @returns {Object.<String,module:ui/view~View>}
461
- */
462
- _createBorderFields() {
463
- const defaultTableCellProperties = this.options.defaultTableCellProperties;
464
- const defaultBorder = {
465
- style: defaultTableCellProperties.borderStyle,
466
- width: defaultTableCellProperties.borderWidth,
467
- color: defaultTableCellProperties.borderColor
468
- };
469
-
470
- const colorInputCreator = getLabeledColorInputCreator( {
471
- colorConfig: this.options.borderColors,
472
- columns: 5,
473
- defaultColorValue: defaultBorder.color
474
- } );
475
- const locale = this.locale;
476
- const t = this.t;
477
-
478
- // -- Group label ---------------------------------------------
479
-
480
- const borderRowLabel = new LabelView( locale );
481
- borderRowLabel.text = t( 'Border' );
482
-
483
- // -- Style ---------------------------------------------------
484
-
485
- const styleLabels = getBorderStyleLabels( t );
486
- const borderStyleDropdown = new LabeledFieldView( locale, createLabeledDropdown );
487
- borderStyleDropdown.set( {
488
- label: t( 'Style' ),
489
- class: 'ck-table-form__border-style'
490
- } );
491
-
492
- borderStyleDropdown.fieldView.buttonView.set( {
493
- isOn: false,
494
- withText: true,
495
- tooltip: t( 'Style' )
496
- } );
497
-
498
- borderStyleDropdown.fieldView.buttonView.bind( 'label' ).to( this, 'borderStyle', value => {
499
- return styleLabels[ value ? value : 'none' ];
500
- } );
501
-
502
- borderStyleDropdown.fieldView.on( 'execute', evt => {
503
- this.borderStyle = evt.source._borderStyleValue;
504
- } );
505
-
506
- borderStyleDropdown.bind( 'isEmpty' ).to( this, 'borderStyle', value => !value );
507
-
508
- addListToDropdown( borderStyleDropdown.fieldView, getBorderStyleDefinitions( this, defaultBorder.style ) );
509
-
510
- // -- Width ---------------------------------------------------
511
-
512
- const borderWidthInput = new LabeledFieldView( locale, createLabeledInputText );
513
-
514
- borderWidthInput.set( {
515
- label: t( 'Width' ),
516
- class: 'ck-table-form__border-width'
517
- } );
518
-
519
- borderWidthInput.fieldView.bind( 'value' ).to( this, 'borderWidth' );
520
- borderWidthInput.bind( 'isEnabled' ).to( this, 'borderStyle', isBorderStyleSet );
521
- borderWidthInput.fieldView.on( 'input', () => {
522
- this.borderWidth = borderWidthInput.fieldView.element.value;
523
- } );
524
-
525
- // -- Color ---------------------------------------------------
526
-
527
- const borderColorInput = new LabeledFieldView( locale, colorInputCreator );
528
-
529
- borderColorInput.set( {
530
- label: t( 'Color' ),
531
- class: 'ck-table-form__border-color'
532
- } );
533
-
534
- borderColorInput.fieldView.bind( 'value' ).to( this, 'borderColor' );
535
- borderColorInput.bind( 'isEnabled' ).to( this, 'borderStyle', isBorderStyleSet );
536
-
537
- borderColorInput.fieldView.on( 'input', () => {
538
- this.borderColor = borderColorInput.fieldView.value;
539
- } );
540
-
541
- // Reset the border color and width fields depending on the `border-style` value.
542
- this.on( 'change:borderStyle', ( evt, name, newValue, oldValue ) => {
543
- // When removing the border (`border-style:none`), clear the remaining `border-*` properties.
544
- // See: https://github.com/ckeditor/ckeditor5/issues/6227.
545
- if ( !isBorderStyleSet( newValue ) ) {
546
- this.borderColor = '';
547
- this.borderWidth = '';
548
- }
549
-
550
- // When setting the `border-style` from `none`, set the default `border-color` and `border-width` properties.
551
- if ( !isBorderStyleSet( oldValue ) ) {
552
- this.borderColor = defaultBorder.color;
553
- this.borderWidth = defaultBorder.width;
554
- }
555
- } );
556
-
557
- return {
558
- borderRowLabel,
559
- borderStyleDropdown,
560
- borderColorInput,
561
- borderWidthInput
562
- };
563
- }
564
-
565
- /**
566
- * Creates the following form fields:
567
- *
568
- * * {@link #backgroundInput}.
569
- *
570
- * @private
571
- * @returns {Object.<String,module:ui/view~View>}
572
- */
573
- _createBackgroundFields() {
574
- const locale = this.locale;
575
- const t = this.t;
576
-
577
- // -- Group label ---------------------------------------------
578
-
579
- const backgroundRowLabel = new LabelView( locale );
580
- backgroundRowLabel.text = t( 'Background' );
581
-
582
- // -- Background color input -----------------------------------
583
-
584
- const colorInputCreator = getLabeledColorInputCreator( {
585
- colorConfig: this.options.backgroundColors,
586
- columns: 5,
587
- defaultColorValue: this.options.defaultTableCellProperties.backgroundColor
588
- } );
589
-
590
- const backgroundInput = new LabeledFieldView( locale, colorInputCreator );
591
-
592
- backgroundInput.set( {
593
- label: t( 'Color' ),
594
- class: 'ck-table-cell-properties-form__background'
595
- } );
596
-
597
- backgroundInput.fieldView.bind( 'value' ).to( this, 'backgroundColor' );
598
- backgroundInput.fieldView.on( 'input', () => {
599
- this.backgroundColor = backgroundInput.fieldView.value;
600
- } );
601
-
602
- return {
603
- backgroundRowLabel,
604
- backgroundInput
605
- };
606
- }
607
-
608
- /**
609
- * Creates the following form fields:
610
- *
611
- * * {@link #widthInput}.
612
- * * {@link #heightInput}.
613
- *
614
- * @private
615
- * @returns {module:ui/labeledfield/labeledfieldview~LabeledFieldView}
616
- */
617
- _createDimensionFields() {
618
- const locale = this.locale;
619
- const t = this.t;
620
-
621
- // -- Label ---------------------------------------------------
622
-
623
- const dimensionsLabel = new LabelView( locale );
624
- dimensionsLabel.text = t( 'Dimensions' );
625
-
626
- // -- Width ---------------------------------------------------
627
-
628
- const widthInput = new LabeledFieldView( locale, createLabeledInputText );
629
-
630
- widthInput.set( {
631
- label: t( 'Width' ),
632
- class: 'ck-table-form__dimensions-row__width'
633
- } );
634
-
635
- widthInput.fieldView.bind( 'value' ).to( this, 'width' );
636
- widthInput.fieldView.on( 'input', () => {
637
- this.width = widthInput.fieldView.element.value;
638
- } );
639
-
640
- // -- Operator ---------------------------------------------------
641
-
642
- const operatorLabel = new View( locale );
643
- operatorLabel.setTemplate( {
644
- tag: 'span',
645
- attributes: {
646
- class: [
647
- 'ck-table-form__dimension-operator'
648
- ]
649
- },
650
- children: [
651
- { text: '×' }
652
- ]
653
- } );
654
-
655
- // -- Height ---------------------------------------------------
656
-
657
- const heightInput = new LabeledFieldView( locale, createLabeledInputText );
658
-
659
- heightInput.set( {
660
- label: t( 'Height' ),
661
- class: 'ck-table-form__dimensions-row__height'
662
- } );
663
-
664
- heightInput.fieldView.bind( 'value' ).to( this, 'height' );
665
- heightInput.fieldView.on( 'input', () => {
666
- this.height = heightInput.fieldView.element.value;
667
- } );
668
-
669
- return {
670
- dimensionsLabel,
671
- widthInput,
672
- operatorLabel,
673
- heightInput
674
- };
675
- }
676
-
677
- /**
678
- * Creates the following form fields:
679
- *
680
- * * {@link #paddingInput}.
681
- *
682
- * @private
683
- * @returns {module:ui/labeledfield/labeledfieldview~LabeledFieldView}
684
- */
685
- _createPaddingField() {
686
- const locale = this.locale;
687
- const t = this.t;
688
-
689
- const paddingInput = new LabeledFieldView( locale, createLabeledInputText );
690
-
691
- paddingInput.set( {
692
- label: t( 'Padding' ),
693
- class: 'ck-table-cell-properties-form__padding'
694
- } );
695
-
696
- paddingInput.fieldView.bind( 'value' ).to( this, 'padding' );
697
- paddingInput.fieldView.on( 'input', () => {
698
- this.padding = paddingInput.fieldView.element.value;
699
- } );
700
-
701
- return paddingInput;
702
- }
703
-
704
- /**
705
- * Creates the following form fields:
706
- *
707
- * * {@link #horizontalAlignmentToolbar},
708
- * * {@link #verticalAlignmentToolbar}.
709
- *
710
- * @private
711
- * @returns {Object.<String,module:ui/view~View>}
712
- */
713
- _createAlignmentFields() {
714
- const locale = this.locale;
715
- const t = this.t;
716
-
717
- const alignmentLabel = new LabelView( locale );
718
-
719
- alignmentLabel.text = t( 'Table cell text alignment' );
720
-
721
- // -- Horizontal ---------------------------------------------------
722
-
723
- const horizontalAlignmentToolbar = new ToolbarView( locale );
724
- const isContentRTL = this.locale.contentLanguageDirection === 'rtl';
725
-
726
- horizontalAlignmentToolbar.set( {
727
- isCompact: true,
728
- ariaLabel: t( 'Horizontal text alignment toolbar' )
729
- } );
730
-
731
- fillToolbar( {
732
- view: this,
733
- icons: ALIGNMENT_ICONS,
734
- toolbar: horizontalAlignmentToolbar,
735
- labels: this._horizontalAlignmentLabels,
736
- propertyName: 'horizontalAlignment',
737
- nameToValue: name => {
738
- // For the RTL content, we want to swap the buttons "align to the left" and "align to the right".
739
- if ( isContentRTL ) {
740
- if ( name === 'left' ) {
741
- return 'right';
742
- } else if ( name === 'right' ) {
743
- return 'left';
744
- }
745
- }
746
-
747
- return name;
748
- },
749
- defaultValue: this.options.defaultTableCellProperties.horizontalAlignment
750
- } );
751
-
752
- // -- Vertical -----------------------------------------------------
753
-
754
- const verticalAlignmentToolbar = new ToolbarView( locale );
755
-
756
- verticalAlignmentToolbar.set( {
757
- isCompact: true,
758
- ariaLabel: t( 'Vertical text alignment toolbar' )
759
- } );
760
-
761
- fillToolbar( {
762
- view: this,
763
- icons: ALIGNMENT_ICONS,
764
- toolbar: verticalAlignmentToolbar,
765
- labels: this._verticalAlignmentLabels,
766
- propertyName: 'verticalAlignment',
767
- defaultValue: this.options.defaultTableCellProperties.verticalAlignment
768
- } );
769
-
770
- return {
771
- horizontalAlignmentToolbar,
772
- verticalAlignmentToolbar,
773
- alignmentLabel
774
- };
775
- }
776
-
777
- /**
778
- * Creates the following form controls:
779
- *
780
- * * {@link #saveButtonView},
781
- * * {@link #cancelButtonView}.
782
- *
783
- * @private
784
- * @returns {Object.<String,module:ui/view~View>}
785
- */
786
- _createActionButtons() {
787
- const locale = this.locale;
788
- const t = this.t;
789
- const saveButtonView = new ButtonView( locale );
790
- const cancelButtonView = new ButtonView( locale );
791
- const fieldsThatShouldValidateToSave = [
792
- this.borderWidthInput,
793
- this.borderColorInput,
794
- this.backgroundInput,
795
- this.paddingInput
796
- ];
797
-
798
- saveButtonView.set( {
799
- label: t( 'Save' ),
800
- icon: icons.check,
801
- class: 'ck-button-save',
802
- type: 'submit',
803
- withText: true
804
- } );
805
-
806
- saveButtonView.bind( 'isEnabled' ).toMany( fieldsThatShouldValidateToSave, 'errorText', ( ...errorTexts ) => {
807
- return errorTexts.every( errorText => !errorText );
808
- } );
809
-
810
- cancelButtonView.set( {
811
- label: t( 'Cancel' ),
812
- icon: icons.cancel,
813
- class: 'ck-button-cancel',
814
- withText: true
815
- } );
816
-
817
- cancelButtonView.delegate( 'execute' ).to( this, 'cancel' );
818
-
819
- return {
820
- saveButtonView, cancelButtonView
821
- };
822
- }
823
-
824
- /**
825
- * Provides localized labels for {@link #horizontalAlignmentToolbar} buttons.
826
- *
827
- * @private
828
- * @type {Object.<String,String>}
829
- */
830
- get _horizontalAlignmentLabels() {
831
- const locale = this.locale;
832
- const t = this.t;
833
-
834
- const left = t( 'Align cell text to the left' );
835
- const center = t( 'Align cell text to the center' );
836
- const right = t( 'Align cell text to the right' );
837
- const justify = t( 'Justify cell text' );
838
-
839
- // Returns object with a proper order of labels.
840
- if ( locale.uiLanguageDirection === 'rtl' ) {
841
- return { right, center, left, justify };
842
- } else {
843
- return { left, center, right, justify };
844
- }
845
- }
846
-
847
- /**
848
- * Provides localized labels for {@link #verticalAlignmentToolbar} buttons.
849
- *
850
- * @private
851
- * @type {Object.<String,String>}
852
- */
853
- get _verticalAlignmentLabels() {
854
- const t = this.t;
855
-
856
- return {
857
- top: t( 'Align cell text to the top' ),
858
- middle: t( 'Align cell text to the middle' ),
859
- bottom: t( 'Align cell text to the bottom' )
860
- };
861
- }
30
+ /**
31
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
32
+ * @param options Additional configuration of the view.
33
+ * @param options.borderColors A configuration of the border color palette used by the
34
+ * {@link module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView#borderColorInput}.
35
+ * @param options.backgroundColors A configuration of the background color palette used by the
36
+ * {@link module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView#backgroundInput}.
37
+ * @param options.defaultTableCellProperties The default table cell properties.
38
+ */
39
+ constructor(locale, options) {
40
+ super(locale);
41
+ this.set({
42
+ borderStyle: '',
43
+ borderWidth: '',
44
+ borderColor: '',
45
+ padding: '',
46
+ backgroundColor: '',
47
+ width: '',
48
+ height: '',
49
+ horizontalAlignment: '',
50
+ verticalAlignment: ''
51
+ });
52
+ this.options = options;
53
+ const { borderStyleDropdown, borderWidthInput, borderColorInput, borderRowLabel } = this._createBorderFields();
54
+ const { backgroundRowLabel, backgroundInput } = this._createBackgroundFields();
55
+ const { widthInput, operatorLabel, heightInput, dimensionsLabel } = this._createDimensionFields();
56
+ const { horizontalAlignmentToolbar, verticalAlignmentToolbar, alignmentLabel } = this._createAlignmentFields();
57
+ this.focusTracker = new FocusTracker();
58
+ this.keystrokes = new KeystrokeHandler();
59
+ this.children = this.createCollection();
60
+ this.borderStyleDropdown = borderStyleDropdown;
61
+ this.borderWidthInput = borderWidthInput;
62
+ this.borderColorInput = borderColorInput;
63
+ this.backgroundInput = backgroundInput;
64
+ this.paddingInput = this._createPaddingField();
65
+ this.widthInput = widthInput;
66
+ this.heightInput = heightInput;
67
+ this.horizontalAlignmentToolbar = horizontalAlignmentToolbar;
68
+ this.verticalAlignmentToolbar = verticalAlignmentToolbar;
69
+ // Defer creating to make sure other fields are present and the Save button can
70
+ // bind its #isEnabled to their error messages so there's no way to save unless all
71
+ // fields are valid.
72
+ const { saveButtonView, cancelButtonView } = this._createActionButtons();
73
+ this.saveButtonView = saveButtonView;
74
+ this.cancelButtonView = cancelButtonView;
75
+ this._focusables = new ViewCollection();
76
+ this._focusCycler = new FocusCycler({
77
+ focusables: this._focusables,
78
+ focusTracker: this.focusTracker,
79
+ keystrokeHandler: this.keystrokes,
80
+ actions: {
81
+ // Navigate form fields backwards using the Shift + Tab keystroke.
82
+ focusPrevious: 'shift + tab',
83
+ // Navigate form fields forwards using the Tab key.
84
+ focusNext: 'tab'
85
+ }
86
+ });
87
+ // Form header.
88
+ this.children.add(new FormHeaderView(locale, {
89
+ label: this.t('Cell properties')
90
+ }));
91
+ // Border row.
92
+ this.children.add(new FormRowView(locale, {
93
+ labelView: borderRowLabel,
94
+ children: [
95
+ borderRowLabel,
96
+ borderStyleDropdown,
97
+ borderColorInput,
98
+ borderWidthInput
99
+ ],
100
+ class: 'ck-table-form__border-row'
101
+ }));
102
+ // Background.
103
+ this.children.add(new FormRowView(locale, {
104
+ labelView: backgroundRowLabel,
105
+ children: [
106
+ backgroundRowLabel,
107
+ backgroundInput
108
+ ],
109
+ class: 'ck-table-form__background-row'
110
+ }));
111
+ // Dimensions row and padding.
112
+ this.children.add(new FormRowView(locale, {
113
+ children: [
114
+ // Dimensions row.
115
+ new FormRowView(locale, {
116
+ labelView: dimensionsLabel,
117
+ children: [
118
+ dimensionsLabel,
119
+ widthInput,
120
+ operatorLabel,
121
+ heightInput
122
+ ],
123
+ class: 'ck-table-form__dimensions-row'
124
+ }),
125
+ // Padding row.
126
+ new FormRowView(locale, {
127
+ children: [
128
+ this.paddingInput
129
+ ],
130
+ class: 'ck-table-cell-properties-form__padding-row'
131
+ })
132
+ ]
133
+ }));
134
+ // Text alignment row.
135
+ this.children.add(new FormRowView(locale, {
136
+ labelView: alignmentLabel,
137
+ children: [
138
+ alignmentLabel,
139
+ horizontalAlignmentToolbar,
140
+ verticalAlignmentToolbar
141
+ ],
142
+ class: 'ck-table-cell-properties-form__alignment-row'
143
+ }));
144
+ // Action row.
145
+ this.children.add(new FormRowView(locale, {
146
+ children: [
147
+ this.saveButtonView,
148
+ this.cancelButtonView
149
+ ],
150
+ class: 'ck-table-form__action-row'
151
+ }));
152
+ this.setTemplate({
153
+ tag: 'form',
154
+ attributes: {
155
+ class: [
156
+ 'ck',
157
+ 'ck-form',
158
+ 'ck-table-form',
159
+ 'ck-table-cell-properties-form'
160
+ ],
161
+ // https://github.com/ckeditor/ckeditor5-link/issues/90
162
+ tabindex: '-1'
163
+ },
164
+ children: this.children
165
+ });
166
+ }
167
+ /**
168
+ * @inheritDoc
169
+ */
170
+ render() {
171
+ super.render();
172
+ // Enable the "submit" event for this view. It can be triggered by the #saveButtonView
173
+ // which is of the "submit" DOM "type".
174
+ submitHandler({
175
+ view: this
176
+ });
177
+ [
178
+ this.borderStyleDropdown,
179
+ this.borderColorInput,
180
+ this.borderColorInput.fieldView.dropdownView.buttonView,
181
+ this.borderWidthInput,
182
+ this.backgroundInput,
183
+ this.backgroundInput.fieldView.dropdownView.buttonView,
184
+ this.widthInput,
185
+ this.heightInput,
186
+ this.paddingInput,
187
+ this.horizontalAlignmentToolbar,
188
+ this.verticalAlignmentToolbar,
189
+ this.saveButtonView,
190
+ this.cancelButtonView
191
+ ].forEach(view => {
192
+ // Register the view as focusable.
193
+ this._focusables.add(view);
194
+ // Register the view in the focus tracker.
195
+ this.focusTracker.add(view.element);
196
+ });
197
+ // Mainly for closing using "Esc" and navigation using "Tab".
198
+ this.keystrokes.listenTo(this.element);
199
+ }
200
+ /**
201
+ * @inheritDoc
202
+ */
203
+ destroy() {
204
+ super.destroy();
205
+ this.focusTracker.destroy();
206
+ this.keystrokes.destroy();
207
+ }
208
+ /**
209
+ * Focuses the fist focusable field in the form.
210
+ */
211
+ focus() {
212
+ this._focusCycler.focusFirst();
213
+ }
214
+ /**
215
+ * Creates the following form fields:
216
+ *
217
+ * * {@link #borderStyleDropdown},
218
+ * * {@link #borderWidthInput},
219
+ * * {@link #borderColorInput}.
220
+ */
221
+ _createBorderFields() {
222
+ const defaultTableCellProperties = this.options.defaultTableCellProperties;
223
+ const defaultBorder = {
224
+ style: defaultTableCellProperties.borderStyle,
225
+ width: defaultTableCellProperties.borderWidth,
226
+ color: defaultTableCellProperties.borderColor
227
+ };
228
+ const colorInputCreator = getLabeledColorInputCreator({
229
+ colorConfig: this.options.borderColors,
230
+ columns: 5,
231
+ defaultColorValue: defaultBorder.color
232
+ });
233
+ const locale = this.locale;
234
+ const t = this.t;
235
+ // -- Group label ---------------------------------------------
236
+ const borderRowLabel = new LabelView(locale);
237
+ borderRowLabel.text = t('Border');
238
+ // -- Style ---------------------------------------------------
239
+ const styleLabels = getBorderStyleLabels(t);
240
+ const borderStyleDropdown = new LabeledFieldView(locale, createLabeledDropdown);
241
+ borderStyleDropdown.set({
242
+ label: t('Style'),
243
+ class: 'ck-table-form__border-style'
244
+ });
245
+ borderStyleDropdown.fieldView.buttonView.set({
246
+ isOn: false,
247
+ withText: true,
248
+ tooltip: t('Style')
249
+ });
250
+ borderStyleDropdown.fieldView.buttonView.bind('label').to(this, 'borderStyle', value => {
251
+ return styleLabels[value ? value : 'none'];
252
+ });
253
+ borderStyleDropdown.fieldView.on('execute', evt => {
254
+ this.borderStyle = evt.source._borderStyleValue;
255
+ });
256
+ borderStyleDropdown.bind('isEmpty').to(this, 'borderStyle', value => !value);
257
+ addListToDropdown(borderStyleDropdown.fieldView, getBorderStyleDefinitions(this, defaultBorder.style));
258
+ // -- Width ---------------------------------------------------
259
+ const borderWidthInput = new LabeledFieldView(locale, createLabeledInputText);
260
+ borderWidthInput.set({
261
+ label: t('Width'),
262
+ class: 'ck-table-form__border-width'
263
+ });
264
+ borderWidthInput.fieldView.bind('value').to(this, 'borderWidth');
265
+ borderWidthInput.bind('isEnabled').to(this, 'borderStyle', isBorderStyleSet);
266
+ borderWidthInput.fieldView.on('input', () => {
267
+ this.borderWidth = borderWidthInput.fieldView.element.value;
268
+ });
269
+ // -- Color ---------------------------------------------------
270
+ const borderColorInput = new LabeledFieldView(locale, colorInputCreator);
271
+ borderColorInput.set({
272
+ label: t('Color'),
273
+ class: 'ck-table-form__border-color'
274
+ });
275
+ borderColorInput.fieldView.bind('value').to(this, 'borderColor');
276
+ borderColorInput.bind('isEnabled').to(this, 'borderStyle', isBorderStyleSet);
277
+ borderColorInput.fieldView.on('input', () => {
278
+ this.borderColor = borderColorInput.fieldView.value;
279
+ });
280
+ // Reset the border color and width fields depending on the `border-style` value.
281
+ this.on('change:borderStyle', (evt, name, newValue, oldValue) => {
282
+ // When removing the border (`border-style:none`), clear the remaining `border-*` properties.
283
+ // See: https://github.com/ckeditor/ckeditor5/issues/6227.
284
+ if (!isBorderStyleSet(newValue)) {
285
+ this.borderColor = '';
286
+ this.borderWidth = '';
287
+ }
288
+ // When setting the `border-style` from `none`, set the default `border-color` and `border-width` properties.
289
+ if (!isBorderStyleSet(oldValue)) {
290
+ this.borderColor = defaultBorder.color;
291
+ this.borderWidth = defaultBorder.width;
292
+ }
293
+ });
294
+ return {
295
+ borderRowLabel,
296
+ borderStyleDropdown,
297
+ borderColorInput,
298
+ borderWidthInput
299
+ };
300
+ }
301
+ /**
302
+ * Creates the following form fields:
303
+ *
304
+ * * {@link #backgroundInput}.
305
+ */
306
+ _createBackgroundFields() {
307
+ const locale = this.locale;
308
+ const t = this.t;
309
+ // -- Group label ---------------------------------------------
310
+ const backgroundRowLabel = new LabelView(locale);
311
+ backgroundRowLabel.text = t('Background');
312
+ // -- Background color input -----------------------------------
313
+ const colorInputCreator = getLabeledColorInputCreator({
314
+ colorConfig: this.options.backgroundColors,
315
+ columns: 5,
316
+ defaultColorValue: this.options.defaultTableCellProperties.backgroundColor
317
+ });
318
+ const backgroundInput = new LabeledFieldView(locale, colorInputCreator);
319
+ backgroundInput.set({
320
+ label: t('Color'),
321
+ class: 'ck-table-cell-properties-form__background'
322
+ });
323
+ backgroundInput.fieldView.bind('value').to(this, 'backgroundColor');
324
+ backgroundInput.fieldView.on('input', () => {
325
+ this.backgroundColor = backgroundInput.fieldView.value;
326
+ });
327
+ return {
328
+ backgroundRowLabel,
329
+ backgroundInput
330
+ };
331
+ }
332
+ /**
333
+ * Creates the following form fields:
334
+ *
335
+ * * {@link #widthInput}.
336
+ * * {@link #heightInput}.
337
+ */
338
+ _createDimensionFields() {
339
+ const locale = this.locale;
340
+ const t = this.t;
341
+ // -- Label ---------------------------------------------------
342
+ const dimensionsLabel = new LabelView(locale);
343
+ dimensionsLabel.text = t('Dimensions');
344
+ // -- Width ---------------------------------------------------
345
+ const widthInput = new LabeledFieldView(locale, createLabeledInputText);
346
+ widthInput.set({
347
+ label: t('Width'),
348
+ class: 'ck-table-form__dimensions-row__width'
349
+ });
350
+ widthInput.fieldView.bind('value').to(this, 'width');
351
+ widthInput.fieldView.on('input', () => {
352
+ this.width = widthInput.fieldView.element.value;
353
+ });
354
+ // -- Operator ---------------------------------------------------
355
+ const operatorLabel = new View(locale);
356
+ operatorLabel.setTemplate({
357
+ tag: 'span',
358
+ attributes: {
359
+ class: [
360
+ 'ck-table-form__dimension-operator'
361
+ ]
362
+ },
363
+ children: [
364
+ { text: '×' }
365
+ ]
366
+ });
367
+ // -- Height ---------------------------------------------------
368
+ const heightInput = new LabeledFieldView(locale, createLabeledInputText);
369
+ heightInput.set({
370
+ label: t('Height'),
371
+ class: 'ck-table-form__dimensions-row__height'
372
+ });
373
+ heightInput.fieldView.bind('value').to(this, 'height');
374
+ heightInput.fieldView.on('input', () => {
375
+ this.height = heightInput.fieldView.element.value;
376
+ });
377
+ return {
378
+ dimensionsLabel,
379
+ widthInput,
380
+ operatorLabel,
381
+ heightInput
382
+ };
383
+ }
384
+ /**
385
+ * Creates the following form fields:
386
+ *
387
+ * * {@link #paddingInput}.
388
+ */
389
+ _createPaddingField() {
390
+ const locale = this.locale;
391
+ const t = this.t;
392
+ const paddingInput = new LabeledFieldView(locale, createLabeledInputText);
393
+ paddingInput.set({
394
+ label: t('Padding'),
395
+ class: 'ck-table-cell-properties-form__padding'
396
+ });
397
+ paddingInput.fieldView.bind('value').to(this, 'padding');
398
+ paddingInput.fieldView.on('input', () => {
399
+ this.padding = paddingInput.fieldView.element.value;
400
+ });
401
+ return paddingInput;
402
+ }
403
+ /**
404
+ * Creates the following form fields:
405
+ *
406
+ * * {@link #horizontalAlignmentToolbar},
407
+ * * {@link #verticalAlignmentToolbar}.
408
+ */
409
+ _createAlignmentFields() {
410
+ const locale = this.locale;
411
+ const t = this.t;
412
+ const alignmentLabel = new LabelView(locale);
413
+ alignmentLabel.text = t('Table cell text alignment');
414
+ // -- Horizontal ---------------------------------------------------
415
+ const horizontalAlignmentToolbar = new ToolbarView(locale);
416
+ const isContentRTL = locale.contentLanguageDirection === 'rtl';
417
+ horizontalAlignmentToolbar.set({
418
+ isCompact: true,
419
+ ariaLabel: t('Horizontal text alignment toolbar')
420
+ });
421
+ fillToolbar({
422
+ view: this,
423
+ icons: ALIGNMENT_ICONS,
424
+ toolbar: horizontalAlignmentToolbar,
425
+ labels: this._horizontalAlignmentLabels,
426
+ propertyName: 'horizontalAlignment',
427
+ nameToValue: name => {
428
+ // For the RTL content, we want to swap the buttons "align to the left" and "align to the right".
429
+ if (isContentRTL) {
430
+ if (name === 'left') {
431
+ return 'right';
432
+ }
433
+ else if (name === 'right') {
434
+ return 'left';
435
+ }
436
+ }
437
+ return name;
438
+ },
439
+ defaultValue: this.options.defaultTableCellProperties.horizontalAlignment
440
+ });
441
+ // -- Vertical -----------------------------------------------------
442
+ const verticalAlignmentToolbar = new ToolbarView(locale);
443
+ verticalAlignmentToolbar.set({
444
+ isCompact: true,
445
+ ariaLabel: t('Vertical text alignment toolbar')
446
+ });
447
+ fillToolbar({
448
+ view: this,
449
+ icons: ALIGNMENT_ICONS,
450
+ toolbar: verticalAlignmentToolbar,
451
+ labels: this._verticalAlignmentLabels,
452
+ propertyName: 'verticalAlignment',
453
+ defaultValue: this.options.defaultTableCellProperties.verticalAlignment
454
+ });
455
+ return {
456
+ horizontalAlignmentToolbar,
457
+ verticalAlignmentToolbar,
458
+ alignmentLabel
459
+ };
460
+ }
461
+ /**
462
+ * Creates the following form controls:
463
+ *
464
+ * * {@link #saveButtonView},
465
+ * * {@link #cancelButtonView}.
466
+ */
467
+ _createActionButtons() {
468
+ const locale = this.locale;
469
+ const t = this.t;
470
+ const saveButtonView = new ButtonView(locale);
471
+ const cancelButtonView = new ButtonView(locale);
472
+ const fieldsThatShouldValidateToSave = [
473
+ this.borderWidthInput,
474
+ this.borderColorInput,
475
+ this.backgroundInput,
476
+ this.paddingInput
477
+ ];
478
+ saveButtonView.set({
479
+ label: t('Save'),
480
+ icon: icons.check,
481
+ class: 'ck-button-save',
482
+ type: 'submit',
483
+ withText: true
484
+ });
485
+ saveButtonView.bind('isEnabled').toMany(fieldsThatShouldValidateToSave, 'errorText', (...errorTexts) => {
486
+ return errorTexts.every(errorText => !errorText);
487
+ });
488
+ cancelButtonView.set({
489
+ label: t('Cancel'),
490
+ icon: icons.cancel,
491
+ class: 'ck-button-cancel',
492
+ withText: true
493
+ });
494
+ cancelButtonView.delegate('execute').to(this, 'cancel');
495
+ return {
496
+ saveButtonView, cancelButtonView
497
+ };
498
+ }
499
+ /**
500
+ * Provides localized labels for {@link #horizontalAlignmentToolbar} buttons.
501
+ */
502
+ get _horizontalAlignmentLabels() {
503
+ const locale = this.locale;
504
+ const t = this.t;
505
+ const left = t('Align cell text to the left');
506
+ const center = t('Align cell text to the center');
507
+ const right = t('Align cell text to the right');
508
+ const justify = t('Justify cell text');
509
+ // Returns object with a proper order of labels.
510
+ if (locale.uiLanguageDirection === 'rtl') {
511
+ return { right, center, left, justify };
512
+ }
513
+ else {
514
+ return { left, center, right, justify };
515
+ }
516
+ }
517
+ /**
518
+ * Provides localized labels for {@link #verticalAlignmentToolbar} buttons.
519
+ */
520
+ get _verticalAlignmentLabels() {
521
+ const t = this.t;
522
+ return {
523
+ top: t('Align cell text to the top'),
524
+ middle: t('Align cell text to the middle'),
525
+ bottom: t('Align cell text to the bottom')
526
+ };
527
+ }
862
528
  }
863
-
864
- function isBorderStyleSet( value ) {
865
- return value !== 'none';
529
+ function isBorderStyleSet(value) {
530
+ return value !== 'none';
866
531
  }