@ckeditor/ckeditor5-table 38.0.1 → 38.1.1

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 (168) hide show
  1. package/build/table.js +1 -1
  2. package/build/table.js.map +1 -0
  3. package/package.json +2 -38
  4. package/src/augmentation.d.ts +76 -76
  5. package/src/augmentation.js +5 -5
  6. package/src/commands/insertcolumncommand.d.ts +55 -55
  7. package/src/commands/insertcolumncommand.js +67 -67
  8. package/src/commands/insertrowcommand.d.ts +54 -54
  9. package/src/commands/insertrowcommand.js +66 -66
  10. package/src/commands/inserttablecommand.d.ts +44 -44
  11. package/src/commands/inserttablecommand.js +69 -69
  12. package/src/commands/mergecellcommand.d.ts +68 -68
  13. package/src/commands/mergecellcommand.js +198 -198
  14. package/src/commands/mergecellscommand.d.ts +28 -28
  15. package/src/commands/mergecellscommand.js +94 -94
  16. package/src/commands/removecolumncommand.d.ts +29 -29
  17. package/src/commands/removecolumncommand.js +109 -109
  18. package/src/commands/removerowcommand.d.ts +29 -29
  19. package/src/commands/removerowcommand.js +82 -82
  20. package/src/commands/selectcolumncommand.d.ts +33 -33
  21. package/src/commands/selectcolumncommand.js +60 -60
  22. package/src/commands/selectrowcommand.d.ts +33 -33
  23. package/src/commands/selectrowcommand.js +56 -56
  24. package/src/commands/setheadercolumncommand.d.ts +50 -50
  25. package/src/commands/setheadercolumncommand.js +71 -71
  26. package/src/commands/setheaderrowcommand.d.ts +53 -53
  27. package/src/commands/setheaderrowcommand.js +79 -79
  28. package/src/commands/splitcellcommand.d.ts +43 -43
  29. package/src/commands/splitcellcommand.js +54 -54
  30. package/src/converters/downcast.d.ts +63 -63
  31. package/src/converters/downcast.js +146 -146
  32. package/src/converters/table-caption-post-fixer.d.ts +20 -20
  33. package/src/converters/table-caption-post-fixer.js +53 -53
  34. package/src/converters/table-cell-paragraph-post-fixer.d.ts +32 -32
  35. package/src/converters/table-cell-paragraph-post-fixer.js +107 -107
  36. package/src/converters/table-cell-refresh-handler.d.ts +18 -18
  37. package/src/converters/table-cell-refresh-handler.js +45 -45
  38. package/src/converters/table-headings-refresh-handler.d.ts +17 -17
  39. package/src/converters/table-headings-refresh-handler.js +49 -49
  40. package/src/converters/table-layout-post-fixer.d.ts +226 -226
  41. package/src/converters/table-layout-post-fixer.js +367 -367
  42. package/src/converters/tableproperties.d.ts +54 -54
  43. package/src/converters/tableproperties.js +159 -159
  44. package/src/converters/upcasttable.d.ts +49 -49
  45. package/src/converters/upcasttable.js +243 -243
  46. package/src/index.d.ts +60 -60
  47. package/src/index.js +30 -30
  48. package/src/plaintableoutput.d.ts +26 -26
  49. package/src/plaintableoutput.js +123 -123
  50. package/src/table.d.ts +40 -40
  51. package/src/table.js +44 -44
  52. package/src/tablecaption/tablecaptionediting.d.ts +63 -63
  53. package/src/tablecaption/tablecaptionediting.js +122 -122
  54. package/src/tablecaption/tablecaptionui.d.ts +21 -21
  55. package/src/tablecaption/tablecaptionui.js +57 -57
  56. package/src/tablecaption/toggletablecaptioncommand.d.ts +68 -68
  57. package/src/tablecaption/toggletablecaptioncommand.js +104 -104
  58. package/src/tablecaption/utils.d.ts +42 -42
  59. package/src/tablecaption/utils.js +67 -67
  60. package/src/tablecaption.d.ts +24 -24
  61. package/src/tablecaption.js +28 -28
  62. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.d.ts +32 -32
  63. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +30 -30
  64. package/src/tablecellproperties/commands/tablecellbordercolorcommand.d.ts +37 -37
  65. package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +44 -44
  66. package/src/tablecellproperties/commands/tablecellborderstylecommand.d.ts +37 -37
  67. package/src/tablecellproperties/commands/tablecellborderstylecommand.js +44 -44
  68. package/src/tablecellproperties/commands/tablecellborderwidthcommand.d.ts +51 -51
  69. package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +64 -64
  70. package/src/tablecellproperties/commands/tablecellheightcommand.d.ts +46 -46
  71. package/src/tablecellproperties/commands/tablecellheightcommand.js +51 -51
  72. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.d.ts +32 -32
  73. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +30 -30
  74. package/src/tablecellproperties/commands/tablecellpaddingcommand.d.ts +51 -51
  75. package/src/tablecellproperties/commands/tablecellpaddingcommand.js +64 -64
  76. package/src/tablecellproperties/commands/tablecellpropertycommand.d.ts +62 -62
  77. package/src/tablecellproperties/commands/tablecellpropertycommand.js +92 -92
  78. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.d.ts +40 -40
  79. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +38 -38
  80. package/src/tablecellproperties/tablecellpropertiesediting.d.ts +43 -43
  81. package/src/tablecellproperties/tablecellpropertiesediting.js +241 -241
  82. package/src/tablecellproperties/tablecellpropertiesui.d.ts +112 -112
  83. package/src/tablecellproperties/tablecellpropertiesui.js +328 -328
  84. package/src/tablecellproperties/ui/tablecellpropertiesview.d.ts +227 -227
  85. package/src/tablecellproperties/ui/tablecellpropertiesview.js +537 -537
  86. package/src/tablecellproperties.d.ts +30 -30
  87. package/src/tablecellproperties.js +34 -34
  88. package/src/tablecellwidth/commands/tablecellwidthcommand.d.ts +46 -46
  89. package/src/tablecellwidth/commands/tablecellwidthcommand.js +51 -51
  90. package/src/tablecellwidth/tablecellwidthediting.d.ts +29 -29
  91. package/src/tablecellwidth/tablecellwidthediting.js +45 -45
  92. package/src/tableclipboard.d.ts +65 -65
  93. package/src/tableclipboard.js +450 -450
  94. package/src/tablecolumnresize/constants.d.ts +20 -20
  95. package/src/tablecolumnresize/constants.js +20 -20
  96. package/src/tablecolumnresize/converters.d.ts +18 -18
  97. package/src/tablecolumnresize/converters.js +45 -45
  98. package/src/tablecolumnresize/tablecolumnresizeediting.d.ts +139 -139
  99. package/src/tablecolumnresize/tablecolumnresizeediting.js +571 -571
  100. package/src/tablecolumnresize/tablewidthscommand.d.ts +38 -38
  101. package/src/tablecolumnresize/tablewidthscommand.js +61 -61
  102. package/src/tablecolumnresize/utils.d.ts +141 -141
  103. package/src/tablecolumnresize/utils.js +330 -330
  104. package/src/tablecolumnresize.d.ts +26 -26
  105. package/src/tablecolumnresize.js +30 -30
  106. package/src/tableconfig.d.ts +331 -331
  107. package/src/tableconfig.js +5 -5
  108. package/src/tableediting.d.ts +98 -98
  109. package/src/tableediting.js +191 -191
  110. package/src/tablekeyboard.d.ts +68 -68
  111. package/src/tablekeyboard.js +279 -279
  112. package/src/tablemouse/mouseeventsobserver.d.ts +62 -62
  113. package/src/tablemouse/mouseeventsobserver.js +35 -35
  114. package/src/tablemouse.d.ts +48 -48
  115. package/src/tablemouse.js +172 -172
  116. package/src/tableproperties/commands/tablealignmentcommand.d.ts +32 -32
  117. package/src/tableproperties/commands/tablealignmentcommand.js +30 -30
  118. package/src/tableproperties/commands/tablebackgroundcolorcommand.d.ts +32 -32
  119. package/src/tableproperties/commands/tablebackgroundcolorcommand.js +30 -30
  120. package/src/tableproperties/commands/tablebordercolorcommand.d.ts +37 -37
  121. package/src/tableproperties/commands/tablebordercolorcommand.js +44 -44
  122. package/src/tableproperties/commands/tableborderstylecommand.d.ts +37 -37
  123. package/src/tableproperties/commands/tableborderstylecommand.js +44 -44
  124. package/src/tableproperties/commands/tableborderwidthcommand.d.ts +51 -51
  125. package/src/tableproperties/commands/tableborderwidthcommand.js +64 -64
  126. package/src/tableproperties/commands/tableheightcommand.d.ts +46 -46
  127. package/src/tableproperties/commands/tableheightcommand.js +54 -54
  128. package/src/tableproperties/commands/tablepropertycommand.d.ts +61 -61
  129. package/src/tableproperties/commands/tablepropertycommand.js +80 -80
  130. package/src/tableproperties/commands/tablewidthcommand.d.ts +46 -46
  131. package/src/tableproperties/commands/tablewidthcommand.js +54 -54
  132. package/src/tableproperties/tablepropertiesediting.d.ts +40 -40
  133. package/src/tableproperties/tablepropertiesediting.js +206 -206
  134. package/src/tableproperties/tablepropertiesui.d.ts +114 -114
  135. package/src/tableproperties/tablepropertiesui.js +319 -319
  136. package/src/tableproperties/ui/tablepropertiesview.d.ts +203 -203
  137. package/src/tableproperties/ui/tablepropertiesview.js +455 -455
  138. package/src/tableproperties.d.ts +30 -30
  139. package/src/tableproperties.js +34 -34
  140. package/src/tableselection.d.ts +107 -107
  141. package/src/tableselection.js +297 -297
  142. package/src/tabletoolbar.d.ts +32 -32
  143. package/src/tabletoolbar.js +57 -57
  144. package/src/tableui.d.ts +53 -53
  145. package/src/tableui.js +309 -309
  146. package/src/tableutils.d.ts +448 -448
  147. package/src/tableutils.js +1041 -1041
  148. package/src/tablewalker.d.ts +323 -323
  149. package/src/tablewalker.js +333 -333
  150. package/src/ui/colorinputview.d.ts +143 -143
  151. package/src/ui/colorinputview.js +248 -248
  152. package/src/ui/formrowview.d.ts +61 -61
  153. package/src/ui/formrowview.js +57 -57
  154. package/src/ui/inserttableview.d.ts +77 -77
  155. package/src/ui/inserttableview.js +169 -169
  156. package/src/utils/common.d.ts +42 -42
  157. package/src/utils/common.js +57 -57
  158. package/src/utils/structure.d.ts +245 -245
  159. package/src/utils/structure.js +426 -426
  160. package/src/utils/table-properties.d.ts +67 -67
  161. package/src/utils/table-properties.js +86 -86
  162. package/src/utils/ui/contextualballoon.d.ts +34 -34
  163. package/src/utils/ui/contextualballoon.js +106 -106
  164. package/src/utils/ui/table-properties.d.ts +193 -193
  165. package/src/utils/ui/table-properties.js +360 -360
  166. package/src/utils/ui/widget.d.ts +16 -16
  167. package/src/utils/ui/widget.js +38 -38
  168. package/theme/tablecolumnresize.css +3 -0
@@ -1,537 +1,537 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module table/tablecellproperties/ui/tablecellpropertiesview
7
- */
8
- import { addListToDropdown, ButtonView, createLabeledDropdown, createLabeledInputText, FocusCycler, FormHeaderView, LabeledFieldView, LabelView, submitHandler, ToolbarView, View, ViewCollection } from 'ckeditor5/src/ui';
9
- import { KeystrokeHandler, FocusTracker } from 'ckeditor5/src/utils';
10
- import { icons } from 'ckeditor5/src/core';
11
- import { fillToolbar, getBorderStyleDefinitions, getBorderStyleLabels, getLabeledColorInputCreator } from '../../utils/ui/table-properties';
12
- import FormRowView from '../../ui/formrowview';
13
- import '../../../theme/form.css';
14
- import '../../../theme/tableform.css';
15
- import '../../../theme/tablecellproperties.css';
16
- const ALIGNMENT_ICONS = {
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
24
- };
25
- /**
26
- * The class representing a table cell properties form, allowing users to customize
27
- * certain style aspects of a table cell, for instance, border, padding, text alignment, etc..
28
- */
29
- export default class TableCellPropertiesView extends View {
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
- const accessibleLabel = t('Style');
236
- // -- Group label ---------------------------------------------
237
- const borderRowLabel = new LabelView(locale);
238
- borderRowLabel.text = t('Border');
239
- // -- Style ---------------------------------------------------
240
- const styleLabels = getBorderStyleLabels(t);
241
- const borderStyleDropdown = new LabeledFieldView(locale, createLabeledDropdown);
242
- borderStyleDropdown.set({
243
- label: accessibleLabel,
244
- class: 'ck-table-form__border-style'
245
- });
246
- borderStyleDropdown.fieldView.buttonView.set({
247
- ariaLabel: accessibleLabel,
248
- ariaLabelledBy: undefined,
249
- isOn: false,
250
- withText: true,
251
- tooltip: accessibleLabel
252
- });
253
- borderStyleDropdown.fieldView.buttonView.bind('label').to(this, 'borderStyle', value => {
254
- return styleLabels[value ? value : 'none'];
255
- });
256
- borderStyleDropdown.fieldView.on('execute', evt => {
257
- this.borderStyle = evt.source._borderStyleValue;
258
- });
259
- borderStyleDropdown.bind('isEmpty').to(this, 'borderStyle', value => !value);
260
- addListToDropdown(borderStyleDropdown.fieldView, getBorderStyleDefinitions(this, defaultBorder.style), {
261
- role: 'menu',
262
- ariaLabel: accessibleLabel
263
- });
264
- // -- Width ---------------------------------------------------
265
- const borderWidthInput = new LabeledFieldView(locale, createLabeledInputText);
266
- borderWidthInput.set({
267
- label: t('Width'),
268
- class: 'ck-table-form__border-width'
269
- });
270
- borderWidthInput.fieldView.bind('value').to(this, 'borderWidth');
271
- borderWidthInput.bind('isEnabled').to(this, 'borderStyle', isBorderStyleSet);
272
- borderWidthInput.fieldView.on('input', () => {
273
- this.borderWidth = borderWidthInput.fieldView.element.value;
274
- });
275
- // -- Color ---------------------------------------------------
276
- const borderColorInput = new LabeledFieldView(locale, colorInputCreator);
277
- borderColorInput.set({
278
- label: t('Color'),
279
- class: 'ck-table-form__border-color'
280
- });
281
- borderColorInput.fieldView.bind('value').to(this, 'borderColor');
282
- borderColorInput.bind('isEnabled').to(this, 'borderStyle', isBorderStyleSet);
283
- borderColorInput.fieldView.on('input', () => {
284
- this.borderColor = borderColorInput.fieldView.value;
285
- });
286
- // Reset the border color and width fields depending on the `border-style` value.
287
- this.on('change:borderStyle', (evt, name, newValue, oldValue) => {
288
- // When removing the border (`border-style:none`), clear the remaining `border-*` properties.
289
- // See: https://github.com/ckeditor/ckeditor5/issues/6227.
290
- if (!isBorderStyleSet(newValue)) {
291
- this.borderColor = '';
292
- this.borderWidth = '';
293
- }
294
- // When setting the `border-style` from `none`, set the default `border-color` and `border-width` properties.
295
- if (!isBorderStyleSet(oldValue)) {
296
- this.borderColor = defaultBorder.color;
297
- this.borderWidth = defaultBorder.width;
298
- }
299
- });
300
- return {
301
- borderRowLabel,
302
- borderStyleDropdown,
303
- borderColorInput,
304
- borderWidthInput
305
- };
306
- }
307
- /**
308
- * Creates the following form fields:
309
- *
310
- * * {@link #backgroundInput}.
311
- */
312
- _createBackgroundFields() {
313
- const locale = this.locale;
314
- const t = this.t;
315
- // -- Group label ---------------------------------------------
316
- const backgroundRowLabel = new LabelView(locale);
317
- backgroundRowLabel.text = t('Background');
318
- // -- Background color input -----------------------------------
319
- const colorInputCreator = getLabeledColorInputCreator({
320
- colorConfig: this.options.backgroundColors,
321
- columns: 5,
322
- defaultColorValue: this.options.defaultTableCellProperties.backgroundColor
323
- });
324
- const backgroundInput = new LabeledFieldView(locale, colorInputCreator);
325
- backgroundInput.set({
326
- label: t('Color'),
327
- class: 'ck-table-cell-properties-form__background'
328
- });
329
- backgroundInput.fieldView.bind('value').to(this, 'backgroundColor');
330
- backgroundInput.fieldView.on('input', () => {
331
- this.backgroundColor = backgroundInput.fieldView.value;
332
- });
333
- return {
334
- backgroundRowLabel,
335
- backgroundInput
336
- };
337
- }
338
- /**
339
- * Creates the following form fields:
340
- *
341
- * * {@link #widthInput}.
342
- * * {@link #heightInput}.
343
- */
344
- _createDimensionFields() {
345
- const locale = this.locale;
346
- const t = this.t;
347
- // -- Label ---------------------------------------------------
348
- const dimensionsLabel = new LabelView(locale);
349
- dimensionsLabel.text = t('Dimensions');
350
- // -- Width ---------------------------------------------------
351
- const widthInput = new LabeledFieldView(locale, createLabeledInputText);
352
- widthInput.set({
353
- label: t('Width'),
354
- class: 'ck-table-form__dimensions-row__width'
355
- });
356
- widthInput.fieldView.bind('value').to(this, 'width');
357
- widthInput.fieldView.on('input', () => {
358
- this.width = widthInput.fieldView.element.value;
359
- });
360
- // -- Operator ---------------------------------------------------
361
- const operatorLabel = new View(locale);
362
- operatorLabel.setTemplate({
363
- tag: 'span',
364
- attributes: {
365
- class: [
366
- 'ck-table-form__dimension-operator'
367
- ]
368
- },
369
- children: [
370
- { text: '×' }
371
- ]
372
- });
373
- // -- Height ---------------------------------------------------
374
- const heightInput = new LabeledFieldView(locale, createLabeledInputText);
375
- heightInput.set({
376
- label: t('Height'),
377
- class: 'ck-table-form__dimensions-row__height'
378
- });
379
- heightInput.fieldView.bind('value').to(this, 'height');
380
- heightInput.fieldView.on('input', () => {
381
- this.height = heightInput.fieldView.element.value;
382
- });
383
- return {
384
- dimensionsLabel,
385
- widthInput,
386
- operatorLabel,
387
- heightInput
388
- };
389
- }
390
- /**
391
- * Creates the following form fields:
392
- *
393
- * * {@link #paddingInput}.
394
- */
395
- _createPaddingField() {
396
- const locale = this.locale;
397
- const t = this.t;
398
- const paddingInput = new LabeledFieldView(locale, createLabeledInputText);
399
- paddingInput.set({
400
- label: t('Padding'),
401
- class: 'ck-table-cell-properties-form__padding'
402
- });
403
- paddingInput.fieldView.bind('value').to(this, 'padding');
404
- paddingInput.fieldView.on('input', () => {
405
- this.padding = paddingInput.fieldView.element.value;
406
- });
407
- return paddingInput;
408
- }
409
- /**
410
- * Creates the following form fields:
411
- *
412
- * * {@link #horizontalAlignmentToolbar},
413
- * * {@link #verticalAlignmentToolbar}.
414
- */
415
- _createAlignmentFields() {
416
- const locale = this.locale;
417
- const t = this.t;
418
- const alignmentLabel = new LabelView(locale);
419
- alignmentLabel.text = t('Table cell text alignment');
420
- // -- Horizontal ---------------------------------------------------
421
- const horizontalAlignmentToolbar = new ToolbarView(locale);
422
- const isContentRTL = locale.contentLanguageDirection === 'rtl';
423
- horizontalAlignmentToolbar.set({
424
- isCompact: true,
425
- ariaLabel: t('Horizontal text alignment toolbar')
426
- });
427
- fillToolbar({
428
- view: this,
429
- icons: ALIGNMENT_ICONS,
430
- toolbar: horizontalAlignmentToolbar,
431
- labels: this._horizontalAlignmentLabels,
432
- propertyName: 'horizontalAlignment',
433
- nameToValue: name => {
434
- // For the RTL content, we want to swap the buttons "align to the left" and "align to the right".
435
- if (isContentRTL) {
436
- if (name === 'left') {
437
- return 'right';
438
- }
439
- else if (name === 'right') {
440
- return 'left';
441
- }
442
- }
443
- return name;
444
- },
445
- defaultValue: this.options.defaultTableCellProperties.horizontalAlignment
446
- });
447
- // -- Vertical -----------------------------------------------------
448
- const verticalAlignmentToolbar = new ToolbarView(locale);
449
- verticalAlignmentToolbar.set({
450
- isCompact: true,
451
- ariaLabel: t('Vertical text alignment toolbar')
452
- });
453
- fillToolbar({
454
- view: this,
455
- icons: ALIGNMENT_ICONS,
456
- toolbar: verticalAlignmentToolbar,
457
- labels: this._verticalAlignmentLabels,
458
- propertyName: 'verticalAlignment',
459
- defaultValue: this.options.defaultTableCellProperties.verticalAlignment
460
- });
461
- return {
462
- horizontalAlignmentToolbar,
463
- verticalAlignmentToolbar,
464
- alignmentLabel
465
- };
466
- }
467
- /**
468
- * Creates the following form controls:
469
- *
470
- * * {@link #saveButtonView},
471
- * * {@link #cancelButtonView}.
472
- */
473
- _createActionButtons() {
474
- const locale = this.locale;
475
- const t = this.t;
476
- const saveButtonView = new ButtonView(locale);
477
- const cancelButtonView = new ButtonView(locale);
478
- const fieldsThatShouldValidateToSave = [
479
- this.borderWidthInput,
480
- this.borderColorInput,
481
- this.backgroundInput,
482
- this.paddingInput
483
- ];
484
- saveButtonView.set({
485
- label: t('Save'),
486
- icon: icons.check,
487
- class: 'ck-button-save',
488
- type: 'submit',
489
- withText: true
490
- });
491
- saveButtonView.bind('isEnabled').toMany(fieldsThatShouldValidateToSave, 'errorText', (...errorTexts) => {
492
- return errorTexts.every(errorText => !errorText);
493
- });
494
- cancelButtonView.set({
495
- label: t('Cancel'),
496
- icon: icons.cancel,
497
- class: 'ck-button-cancel',
498
- withText: true
499
- });
500
- cancelButtonView.delegate('execute').to(this, 'cancel');
501
- return {
502
- saveButtonView, cancelButtonView
503
- };
504
- }
505
- /**
506
- * Provides localized labels for {@link #horizontalAlignmentToolbar} buttons.
507
- */
508
- get _horizontalAlignmentLabels() {
509
- const locale = this.locale;
510
- const t = this.t;
511
- const left = t('Align cell text to the left');
512
- const center = t('Align cell text to the center');
513
- const right = t('Align cell text to the right');
514
- const justify = t('Justify cell text');
515
- // Returns object with a proper order of labels.
516
- if (locale.uiLanguageDirection === 'rtl') {
517
- return { right, center, left, justify };
518
- }
519
- else {
520
- return { left, center, right, justify };
521
- }
522
- }
523
- /**
524
- * Provides localized labels for {@link #verticalAlignmentToolbar} buttons.
525
- */
526
- get _verticalAlignmentLabels() {
527
- const t = this.t;
528
- return {
529
- top: t('Align cell text to the top'),
530
- middle: t('Align cell text to the middle'),
531
- bottom: t('Align cell text to the bottom')
532
- };
533
- }
534
- }
535
- function isBorderStyleSet(value) {
536
- return value !== 'none';
537
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module table/tablecellproperties/ui/tablecellpropertiesview
7
+ */
8
+ import { addListToDropdown, ButtonView, createLabeledDropdown, createLabeledInputText, FocusCycler, FormHeaderView, LabeledFieldView, LabelView, submitHandler, ToolbarView, View, ViewCollection } from 'ckeditor5/src/ui';
9
+ import { KeystrokeHandler, FocusTracker } from 'ckeditor5/src/utils';
10
+ import { icons } from 'ckeditor5/src/core';
11
+ import { fillToolbar, getBorderStyleDefinitions, getBorderStyleLabels, getLabeledColorInputCreator } from '../../utils/ui/table-properties';
12
+ import FormRowView from '../../ui/formrowview';
13
+ import '../../../theme/form.css';
14
+ import '../../../theme/tableform.css';
15
+ import '../../../theme/tablecellproperties.css';
16
+ const ALIGNMENT_ICONS = {
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
24
+ };
25
+ /**
26
+ * The class representing a table cell properties form, allowing users to customize
27
+ * certain style aspects of a table cell, for instance, border, padding, text alignment, etc..
28
+ */
29
+ export default class TableCellPropertiesView extends View {
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
+ const accessibleLabel = t('Style');
236
+ // -- Group label ---------------------------------------------
237
+ const borderRowLabel = new LabelView(locale);
238
+ borderRowLabel.text = t('Border');
239
+ // -- Style ---------------------------------------------------
240
+ const styleLabels = getBorderStyleLabels(t);
241
+ const borderStyleDropdown = new LabeledFieldView(locale, createLabeledDropdown);
242
+ borderStyleDropdown.set({
243
+ label: accessibleLabel,
244
+ class: 'ck-table-form__border-style'
245
+ });
246
+ borderStyleDropdown.fieldView.buttonView.set({
247
+ ariaLabel: accessibleLabel,
248
+ ariaLabelledBy: undefined,
249
+ isOn: false,
250
+ withText: true,
251
+ tooltip: accessibleLabel
252
+ });
253
+ borderStyleDropdown.fieldView.buttonView.bind('label').to(this, 'borderStyle', value => {
254
+ return styleLabels[value ? value : 'none'];
255
+ });
256
+ borderStyleDropdown.fieldView.on('execute', evt => {
257
+ this.borderStyle = evt.source._borderStyleValue;
258
+ });
259
+ borderStyleDropdown.bind('isEmpty').to(this, 'borderStyle', value => !value);
260
+ addListToDropdown(borderStyleDropdown.fieldView, getBorderStyleDefinitions(this, defaultBorder.style), {
261
+ role: 'menu',
262
+ ariaLabel: accessibleLabel
263
+ });
264
+ // -- Width ---------------------------------------------------
265
+ const borderWidthInput = new LabeledFieldView(locale, createLabeledInputText);
266
+ borderWidthInput.set({
267
+ label: t('Width'),
268
+ class: 'ck-table-form__border-width'
269
+ });
270
+ borderWidthInput.fieldView.bind('value').to(this, 'borderWidth');
271
+ borderWidthInput.bind('isEnabled').to(this, 'borderStyle', isBorderStyleSet);
272
+ borderWidthInput.fieldView.on('input', () => {
273
+ this.borderWidth = borderWidthInput.fieldView.element.value;
274
+ });
275
+ // -- Color ---------------------------------------------------
276
+ const borderColorInput = new LabeledFieldView(locale, colorInputCreator);
277
+ borderColorInput.set({
278
+ label: t('Color'),
279
+ class: 'ck-table-form__border-color'
280
+ });
281
+ borderColorInput.fieldView.bind('value').to(this, 'borderColor');
282
+ borderColorInput.bind('isEnabled').to(this, 'borderStyle', isBorderStyleSet);
283
+ borderColorInput.fieldView.on('input', () => {
284
+ this.borderColor = borderColorInput.fieldView.value;
285
+ });
286
+ // Reset the border color and width fields depending on the `border-style` value.
287
+ this.on('change:borderStyle', (evt, name, newValue, oldValue) => {
288
+ // When removing the border (`border-style:none`), clear the remaining `border-*` properties.
289
+ // See: https://github.com/ckeditor/ckeditor5/issues/6227.
290
+ if (!isBorderStyleSet(newValue)) {
291
+ this.borderColor = '';
292
+ this.borderWidth = '';
293
+ }
294
+ // When setting the `border-style` from `none`, set the default `border-color` and `border-width` properties.
295
+ if (!isBorderStyleSet(oldValue)) {
296
+ this.borderColor = defaultBorder.color;
297
+ this.borderWidth = defaultBorder.width;
298
+ }
299
+ });
300
+ return {
301
+ borderRowLabel,
302
+ borderStyleDropdown,
303
+ borderColorInput,
304
+ borderWidthInput
305
+ };
306
+ }
307
+ /**
308
+ * Creates the following form fields:
309
+ *
310
+ * * {@link #backgroundInput}.
311
+ */
312
+ _createBackgroundFields() {
313
+ const locale = this.locale;
314
+ const t = this.t;
315
+ // -- Group label ---------------------------------------------
316
+ const backgroundRowLabel = new LabelView(locale);
317
+ backgroundRowLabel.text = t('Background');
318
+ // -- Background color input -----------------------------------
319
+ const colorInputCreator = getLabeledColorInputCreator({
320
+ colorConfig: this.options.backgroundColors,
321
+ columns: 5,
322
+ defaultColorValue: this.options.defaultTableCellProperties.backgroundColor
323
+ });
324
+ const backgroundInput = new LabeledFieldView(locale, colorInputCreator);
325
+ backgroundInput.set({
326
+ label: t('Color'),
327
+ class: 'ck-table-cell-properties-form__background'
328
+ });
329
+ backgroundInput.fieldView.bind('value').to(this, 'backgroundColor');
330
+ backgroundInput.fieldView.on('input', () => {
331
+ this.backgroundColor = backgroundInput.fieldView.value;
332
+ });
333
+ return {
334
+ backgroundRowLabel,
335
+ backgroundInput
336
+ };
337
+ }
338
+ /**
339
+ * Creates the following form fields:
340
+ *
341
+ * * {@link #widthInput}.
342
+ * * {@link #heightInput}.
343
+ */
344
+ _createDimensionFields() {
345
+ const locale = this.locale;
346
+ const t = this.t;
347
+ // -- Label ---------------------------------------------------
348
+ const dimensionsLabel = new LabelView(locale);
349
+ dimensionsLabel.text = t('Dimensions');
350
+ // -- Width ---------------------------------------------------
351
+ const widthInput = new LabeledFieldView(locale, createLabeledInputText);
352
+ widthInput.set({
353
+ label: t('Width'),
354
+ class: 'ck-table-form__dimensions-row__width'
355
+ });
356
+ widthInput.fieldView.bind('value').to(this, 'width');
357
+ widthInput.fieldView.on('input', () => {
358
+ this.width = widthInput.fieldView.element.value;
359
+ });
360
+ // -- Operator ---------------------------------------------------
361
+ const operatorLabel = new View(locale);
362
+ operatorLabel.setTemplate({
363
+ tag: 'span',
364
+ attributes: {
365
+ class: [
366
+ 'ck-table-form__dimension-operator'
367
+ ]
368
+ },
369
+ children: [
370
+ { text: '×' }
371
+ ]
372
+ });
373
+ // -- Height ---------------------------------------------------
374
+ const heightInput = new LabeledFieldView(locale, createLabeledInputText);
375
+ heightInput.set({
376
+ label: t('Height'),
377
+ class: 'ck-table-form__dimensions-row__height'
378
+ });
379
+ heightInput.fieldView.bind('value').to(this, 'height');
380
+ heightInput.fieldView.on('input', () => {
381
+ this.height = heightInput.fieldView.element.value;
382
+ });
383
+ return {
384
+ dimensionsLabel,
385
+ widthInput,
386
+ operatorLabel,
387
+ heightInput
388
+ };
389
+ }
390
+ /**
391
+ * Creates the following form fields:
392
+ *
393
+ * * {@link #paddingInput}.
394
+ */
395
+ _createPaddingField() {
396
+ const locale = this.locale;
397
+ const t = this.t;
398
+ const paddingInput = new LabeledFieldView(locale, createLabeledInputText);
399
+ paddingInput.set({
400
+ label: t('Padding'),
401
+ class: 'ck-table-cell-properties-form__padding'
402
+ });
403
+ paddingInput.fieldView.bind('value').to(this, 'padding');
404
+ paddingInput.fieldView.on('input', () => {
405
+ this.padding = paddingInput.fieldView.element.value;
406
+ });
407
+ return paddingInput;
408
+ }
409
+ /**
410
+ * Creates the following form fields:
411
+ *
412
+ * * {@link #horizontalAlignmentToolbar},
413
+ * * {@link #verticalAlignmentToolbar}.
414
+ */
415
+ _createAlignmentFields() {
416
+ const locale = this.locale;
417
+ const t = this.t;
418
+ const alignmentLabel = new LabelView(locale);
419
+ alignmentLabel.text = t('Table cell text alignment');
420
+ // -- Horizontal ---------------------------------------------------
421
+ const horizontalAlignmentToolbar = new ToolbarView(locale);
422
+ const isContentRTL = locale.contentLanguageDirection === 'rtl';
423
+ horizontalAlignmentToolbar.set({
424
+ isCompact: true,
425
+ ariaLabel: t('Horizontal text alignment toolbar')
426
+ });
427
+ fillToolbar({
428
+ view: this,
429
+ icons: ALIGNMENT_ICONS,
430
+ toolbar: horizontalAlignmentToolbar,
431
+ labels: this._horizontalAlignmentLabels,
432
+ propertyName: 'horizontalAlignment',
433
+ nameToValue: name => {
434
+ // For the RTL content, we want to swap the buttons "align to the left" and "align to the right".
435
+ if (isContentRTL) {
436
+ if (name === 'left') {
437
+ return 'right';
438
+ }
439
+ else if (name === 'right') {
440
+ return 'left';
441
+ }
442
+ }
443
+ return name;
444
+ },
445
+ defaultValue: this.options.defaultTableCellProperties.horizontalAlignment
446
+ });
447
+ // -- Vertical -----------------------------------------------------
448
+ const verticalAlignmentToolbar = new ToolbarView(locale);
449
+ verticalAlignmentToolbar.set({
450
+ isCompact: true,
451
+ ariaLabel: t('Vertical text alignment toolbar')
452
+ });
453
+ fillToolbar({
454
+ view: this,
455
+ icons: ALIGNMENT_ICONS,
456
+ toolbar: verticalAlignmentToolbar,
457
+ labels: this._verticalAlignmentLabels,
458
+ propertyName: 'verticalAlignment',
459
+ defaultValue: this.options.defaultTableCellProperties.verticalAlignment
460
+ });
461
+ return {
462
+ horizontalAlignmentToolbar,
463
+ verticalAlignmentToolbar,
464
+ alignmentLabel
465
+ };
466
+ }
467
+ /**
468
+ * Creates the following form controls:
469
+ *
470
+ * * {@link #saveButtonView},
471
+ * * {@link #cancelButtonView}.
472
+ */
473
+ _createActionButtons() {
474
+ const locale = this.locale;
475
+ const t = this.t;
476
+ const saveButtonView = new ButtonView(locale);
477
+ const cancelButtonView = new ButtonView(locale);
478
+ const fieldsThatShouldValidateToSave = [
479
+ this.borderWidthInput,
480
+ this.borderColorInput,
481
+ this.backgroundInput,
482
+ this.paddingInput
483
+ ];
484
+ saveButtonView.set({
485
+ label: t('Save'),
486
+ icon: icons.check,
487
+ class: 'ck-button-save',
488
+ type: 'submit',
489
+ withText: true
490
+ });
491
+ saveButtonView.bind('isEnabled').toMany(fieldsThatShouldValidateToSave, 'errorText', (...errorTexts) => {
492
+ return errorTexts.every(errorText => !errorText);
493
+ });
494
+ cancelButtonView.set({
495
+ label: t('Cancel'),
496
+ icon: icons.cancel,
497
+ class: 'ck-button-cancel',
498
+ withText: true
499
+ });
500
+ cancelButtonView.delegate('execute').to(this, 'cancel');
501
+ return {
502
+ saveButtonView, cancelButtonView
503
+ };
504
+ }
505
+ /**
506
+ * Provides localized labels for {@link #horizontalAlignmentToolbar} buttons.
507
+ */
508
+ get _horizontalAlignmentLabels() {
509
+ const locale = this.locale;
510
+ const t = this.t;
511
+ const left = t('Align cell text to the left');
512
+ const center = t('Align cell text to the center');
513
+ const right = t('Align cell text to the right');
514
+ const justify = t('Justify cell text');
515
+ // Returns object with a proper order of labels.
516
+ if (locale.uiLanguageDirection === 'rtl') {
517
+ return { right, center, left, justify };
518
+ }
519
+ else {
520
+ return { left, center, right, justify };
521
+ }
522
+ }
523
+ /**
524
+ * Provides localized labels for {@link #verticalAlignmentToolbar} buttons.
525
+ */
526
+ get _verticalAlignmentLabels() {
527
+ const t = this.t;
528
+ return {
529
+ top: t('Align cell text to the top'),
530
+ middle: t('Align cell text to the middle'),
531
+ bottom: t('Align cell text to the bottom')
532
+ };
533
+ }
534
+ }
535
+ function isBorderStyleSet(value) {
536
+ return value !== 'none';
537
+ }