@ckeditor/ckeditor5-table 40.0.0 → 40.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -15
- package/LICENSE.md +3 -3
- package/build/table.js +1 -1
- package/build/translations/fi.js +1 -1
- package/lang/translations/fi.po +3 -3
- package/package.json +2 -2
- package/src/augmentation.d.ts +76 -76
- package/src/augmentation.js +5 -5
- package/src/commands/insertcolumncommand.d.ts +55 -55
- package/src/commands/insertcolumncommand.js +67 -67
- package/src/commands/insertrowcommand.d.ts +54 -54
- package/src/commands/insertrowcommand.js +66 -66
- package/src/commands/inserttablecommand.d.ts +44 -44
- package/src/commands/inserttablecommand.js +69 -69
- package/src/commands/mergecellcommand.d.ts +68 -68
- package/src/commands/mergecellcommand.js +198 -198
- package/src/commands/mergecellscommand.d.ts +28 -28
- package/src/commands/mergecellscommand.js +94 -94
- package/src/commands/removecolumncommand.d.ts +29 -29
- package/src/commands/removecolumncommand.js +109 -109
- package/src/commands/removerowcommand.d.ts +29 -29
- package/src/commands/removerowcommand.js +82 -82
- package/src/commands/selectcolumncommand.d.ts +33 -33
- package/src/commands/selectcolumncommand.js +60 -60
- package/src/commands/selectrowcommand.d.ts +33 -33
- package/src/commands/selectrowcommand.js +56 -56
- package/src/commands/setheadercolumncommand.d.ts +50 -50
- package/src/commands/setheadercolumncommand.js +71 -71
- package/src/commands/setheaderrowcommand.d.ts +53 -53
- package/src/commands/setheaderrowcommand.js +79 -79
- package/src/commands/splitcellcommand.d.ts +43 -43
- package/src/commands/splitcellcommand.js +54 -54
- package/src/converters/downcast.d.ts +63 -63
- package/src/converters/downcast.js +146 -146
- package/src/converters/table-caption-post-fixer.d.ts +20 -20
- package/src/converters/table-caption-post-fixer.js +53 -53
- package/src/converters/table-cell-paragraph-post-fixer.d.ts +32 -32
- package/src/converters/table-cell-paragraph-post-fixer.js +107 -107
- package/src/converters/table-cell-refresh-handler.d.ts +18 -18
- package/src/converters/table-cell-refresh-handler.js +45 -45
- package/src/converters/table-headings-refresh-handler.d.ts +17 -17
- package/src/converters/table-headings-refresh-handler.js +49 -49
- package/src/converters/table-layout-post-fixer.d.ts +226 -226
- package/src/converters/table-layout-post-fixer.js +367 -367
- package/src/converters/tableproperties.d.ts +54 -54
- package/src/converters/tableproperties.js +159 -159
- package/src/converters/upcasttable.d.ts +49 -49
- package/src/converters/upcasttable.js +243 -243
- package/src/index.d.ts +60 -60
- package/src/index.js +30 -30
- package/src/plaintableoutput.d.ts +26 -26
- package/src/plaintableoutput.js +123 -123
- package/src/table.d.ts +40 -40
- package/src/table.js +44 -44
- package/src/tablecaption/tablecaptionediting.d.ts +63 -63
- package/src/tablecaption/tablecaptionediting.js +122 -122
- package/src/tablecaption/tablecaptionui.d.ts +21 -21
- package/src/tablecaption/tablecaptionui.js +57 -57
- package/src/tablecaption/toggletablecaptioncommand.d.ts +68 -68
- package/src/tablecaption/toggletablecaptioncommand.js +105 -104
- package/src/tablecaption/utils.d.ts +38 -42
- package/src/tablecaption/utils.js +57 -67
- package/src/tablecaption.d.ts +24 -24
- package/src/tablecaption.js +28 -28
- package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.d.ts +32 -32
- package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +30 -30
- package/src/tablecellproperties/commands/tablecellbordercolorcommand.d.ts +37 -37
- package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +44 -44
- package/src/tablecellproperties/commands/tablecellborderstylecommand.d.ts +37 -37
- package/src/tablecellproperties/commands/tablecellborderstylecommand.js +44 -44
- package/src/tablecellproperties/commands/tablecellborderwidthcommand.d.ts +51 -51
- package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +64 -64
- package/src/tablecellproperties/commands/tablecellheightcommand.d.ts +46 -46
- package/src/tablecellproperties/commands/tablecellheightcommand.js +51 -51
- package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.d.ts +32 -32
- package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +30 -30
- package/src/tablecellproperties/commands/tablecellpaddingcommand.d.ts +51 -51
- package/src/tablecellproperties/commands/tablecellpaddingcommand.js +64 -64
- package/src/tablecellproperties/commands/tablecellpropertycommand.d.ts +62 -62
- package/src/tablecellproperties/commands/tablecellpropertycommand.js +92 -92
- package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.d.ts +40 -40
- package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +38 -38
- package/src/tablecellproperties/tablecellpropertiesediting.d.ts +43 -43
- package/src/tablecellproperties/tablecellpropertiesediting.js +241 -241
- package/src/tablecellproperties/tablecellpropertiesui.d.ts +112 -112
- package/src/tablecellproperties/tablecellpropertiesui.js +330 -330
- package/src/tablecellproperties/ui/tablecellpropertiesview.d.ts +228 -228
- package/src/tablecellproperties/ui/tablecellpropertiesview.js +548 -548
- package/src/tablecellproperties.d.ts +30 -30
- package/src/tablecellproperties.js +34 -34
- package/src/tablecellwidth/commands/tablecellwidthcommand.d.ts +46 -46
- package/src/tablecellwidth/commands/tablecellwidthcommand.js +51 -51
- package/src/tablecellwidth/tablecellwidthediting.d.ts +29 -29
- package/src/tablecellwidth/tablecellwidthediting.js +45 -45
- package/src/tableclipboard.d.ts +65 -65
- package/src/tableclipboard.js +450 -450
- package/src/tablecolumnresize/constants.d.ts +20 -20
- package/src/tablecolumnresize/constants.js +20 -20
- package/src/tablecolumnresize/converters.d.ts +18 -18
- package/src/tablecolumnresize/converters.js +46 -46
- package/src/tablecolumnresize/tablecolumnresizeediting.d.ts +139 -139
- package/src/tablecolumnresize/tablecolumnresizeediting.js +583 -583
- package/src/tablecolumnresize/tablewidthscommand.d.ts +38 -38
- package/src/tablecolumnresize/tablewidthscommand.js +61 -61
- package/src/tablecolumnresize/utils.d.ts +148 -148
- package/src/tablecolumnresize/utils.js +358 -358
- package/src/tablecolumnresize.d.ts +26 -26
- package/src/tablecolumnresize.js +30 -30
- package/src/tableconfig.d.ts +343 -343
- package/src/tableconfig.js +5 -5
- package/src/tableediting.d.ts +98 -98
- package/src/tableediting.js +191 -191
- package/src/tablekeyboard.d.ts +68 -68
- package/src/tablekeyboard.js +279 -279
- package/src/tablemouse/mouseeventsobserver.d.ts +62 -62
- package/src/tablemouse/mouseeventsobserver.js +35 -35
- package/src/tablemouse.d.ts +48 -48
- package/src/tablemouse.js +172 -172
- package/src/tableproperties/commands/tablealignmentcommand.d.ts +32 -32
- package/src/tableproperties/commands/tablealignmentcommand.js +30 -30
- package/src/tableproperties/commands/tablebackgroundcolorcommand.d.ts +32 -32
- package/src/tableproperties/commands/tablebackgroundcolorcommand.js +30 -30
- package/src/tableproperties/commands/tablebordercolorcommand.d.ts +37 -37
- package/src/tableproperties/commands/tablebordercolorcommand.js +44 -44
- package/src/tableproperties/commands/tableborderstylecommand.d.ts +37 -37
- package/src/tableproperties/commands/tableborderstylecommand.js +44 -44
- package/src/tableproperties/commands/tableborderwidthcommand.d.ts +51 -51
- package/src/tableproperties/commands/tableborderwidthcommand.js +64 -64
- package/src/tableproperties/commands/tableheightcommand.d.ts +46 -46
- package/src/tableproperties/commands/tableheightcommand.js +54 -54
- package/src/tableproperties/commands/tablepropertycommand.d.ts +61 -61
- package/src/tableproperties/commands/tablepropertycommand.js +81 -80
- package/src/tableproperties/commands/tablewidthcommand.d.ts +46 -46
- package/src/tableproperties/commands/tablewidthcommand.js +54 -54
- package/src/tableproperties/tablepropertiesediting.d.ts +40 -40
- package/src/tableproperties/tablepropertiesediting.js +206 -206
- package/src/tableproperties/tablepropertiesui.d.ts +114 -114
- package/src/tableproperties/tablepropertiesui.js +321 -321
- package/src/tableproperties/ui/tablepropertiesview.d.ts +207 -207
- package/src/tableproperties/ui/tablepropertiesview.js +466 -466
- package/src/tableproperties.d.ts +30 -30
- package/src/tableproperties.js +34 -34
- package/src/tableselection.d.ts +107 -107
- package/src/tableselection.js +297 -297
- package/src/tabletoolbar.d.ts +32 -32
- package/src/tabletoolbar.js +57 -57
- package/src/tableui.d.ts +53 -53
- package/src/tableui.js +309 -309
- package/src/tableutils.d.ts +448 -448
- package/src/tableutils.js +1055 -1055
- package/src/tablewalker.d.ts +362 -362
- package/src/tablewalker.js +393 -393
- package/src/ui/colorinputview.d.ts +140 -140
- package/src/ui/colorinputview.js +271 -271
- package/src/ui/formrowview.d.ts +61 -61
- package/src/ui/formrowview.js +57 -57
- package/src/ui/inserttableview.d.ts +77 -77
- package/src/ui/inserttableview.js +169 -169
- package/src/utils/common.d.ts +46 -42
- package/src/utils/common.js +68 -57
- package/src/utils/structure.d.ts +245 -245
- package/src/utils/structure.js +426 -426
- package/src/utils/table-properties.d.ts +67 -67
- package/src/utils/table-properties.js +86 -86
- package/src/utils/ui/contextualballoon.d.ts +34 -34
- package/src/utils/ui/contextualballoon.js +110 -106
- package/src/utils/ui/table-properties.d.ts +195 -195
- package/src/utils/ui/table-properties.js +362 -362
- package/src/utils/ui/widget.d.ts +20 -16
- package/src/utils/ui/widget.js +48 -38
- package/build/table.js.map +0 -1
|
@@ -1,548 +1,548 @@
|
|
|
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
|
-
// Maintain continuous focus cycling over views that have focusable children and focus cyclers themselves.
|
|
178
|
-
[this.borderColorInput, this.backgroundInput].forEach(view => {
|
|
179
|
-
view.fieldView.focusCycler.on('forwardCycle', evt => {
|
|
180
|
-
this._focusCycler.focusNext();
|
|
181
|
-
evt.stop();
|
|
182
|
-
});
|
|
183
|
-
view.fieldView.focusCycler.on('backwardCycle', evt => {
|
|
184
|
-
this._focusCycler.focusPrevious();
|
|
185
|
-
evt.stop();
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
[
|
|
189
|
-
this.borderStyleDropdown,
|
|
190
|
-
this.borderColorInput,
|
|
191
|
-
this.borderWidthInput,
|
|
192
|
-
this.backgroundInput,
|
|
193
|
-
this.widthInput,
|
|
194
|
-
this.heightInput,
|
|
195
|
-
this.paddingInput,
|
|
196
|
-
this.horizontalAlignmentToolbar,
|
|
197
|
-
this.verticalAlignmentToolbar,
|
|
198
|
-
this.saveButtonView,
|
|
199
|
-
this.cancelButtonView
|
|
200
|
-
].forEach(view => {
|
|
201
|
-
// Register the view as focusable.
|
|
202
|
-
this._focusables.add(view);
|
|
203
|
-
// Register the view in the focus tracker.
|
|
204
|
-
this.focusTracker.add(view.element);
|
|
205
|
-
});
|
|
206
|
-
// Mainly for closing using "Esc" and navigation using "Tab".
|
|
207
|
-
this.keystrokes.listenTo(this.element);
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* @inheritDoc
|
|
211
|
-
*/
|
|
212
|
-
destroy() {
|
|
213
|
-
super.destroy();
|
|
214
|
-
this.focusTracker.destroy();
|
|
215
|
-
this.keystrokes.destroy();
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Focuses the fist focusable field in the form.
|
|
219
|
-
*/
|
|
220
|
-
focus() {
|
|
221
|
-
this._focusCycler.focusFirst();
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Creates the following form fields:
|
|
225
|
-
*
|
|
226
|
-
* * {@link #borderStyleDropdown},
|
|
227
|
-
* * {@link #borderWidthInput},
|
|
228
|
-
* * {@link #borderColorInput}.
|
|
229
|
-
*/
|
|
230
|
-
_createBorderFields() {
|
|
231
|
-
const defaultTableCellProperties = this.options.defaultTableCellProperties;
|
|
232
|
-
const defaultBorder = {
|
|
233
|
-
style: defaultTableCellProperties.borderStyle,
|
|
234
|
-
width: defaultTableCellProperties.borderWidth,
|
|
235
|
-
color: defaultTableCellProperties.borderColor
|
|
236
|
-
};
|
|
237
|
-
const colorInputCreator = getLabeledColorInputCreator({
|
|
238
|
-
colorConfig: this.options.borderColors,
|
|
239
|
-
columns: 5,
|
|
240
|
-
defaultColorValue: defaultBorder.color,
|
|
241
|
-
colorPickerConfig: this.options.colorPickerConfig
|
|
242
|
-
});
|
|
243
|
-
const locale = this.locale;
|
|
244
|
-
const t = this.t;
|
|
245
|
-
const accessibleLabel = t('Style');
|
|
246
|
-
// -- Group label ---------------------------------------------
|
|
247
|
-
const borderRowLabel = new LabelView(locale);
|
|
248
|
-
borderRowLabel.text = t('Border');
|
|
249
|
-
// -- Style ---------------------------------------------------
|
|
250
|
-
const styleLabels = getBorderStyleLabels(t);
|
|
251
|
-
const borderStyleDropdown = new LabeledFieldView(locale, createLabeledDropdown);
|
|
252
|
-
borderStyleDropdown.set({
|
|
253
|
-
label: accessibleLabel,
|
|
254
|
-
class: 'ck-table-form__border-style'
|
|
255
|
-
});
|
|
256
|
-
borderStyleDropdown.fieldView.buttonView.set({
|
|
257
|
-
ariaLabel: accessibleLabel,
|
|
258
|
-
ariaLabelledBy: undefined,
|
|
259
|
-
isOn: false,
|
|
260
|
-
withText: true,
|
|
261
|
-
tooltip: accessibleLabel
|
|
262
|
-
});
|
|
263
|
-
borderStyleDropdown.fieldView.buttonView.bind('label').to(this, 'borderStyle', value => {
|
|
264
|
-
return styleLabels[value ? value : 'none'];
|
|
265
|
-
});
|
|
266
|
-
borderStyleDropdown.fieldView.on('execute', evt => {
|
|
267
|
-
this.borderStyle = evt.source._borderStyleValue;
|
|
268
|
-
});
|
|
269
|
-
borderStyleDropdown.bind('isEmpty').to(this, 'borderStyle', value => !value);
|
|
270
|
-
addListToDropdown(borderStyleDropdown.fieldView, getBorderStyleDefinitions(this, defaultBorder.style), {
|
|
271
|
-
role: 'menu',
|
|
272
|
-
ariaLabel: accessibleLabel
|
|
273
|
-
});
|
|
274
|
-
// -- Width ---------------------------------------------------
|
|
275
|
-
const borderWidthInput = new LabeledFieldView(locale, createLabeledInputText);
|
|
276
|
-
borderWidthInput.set({
|
|
277
|
-
label: t('Width'),
|
|
278
|
-
class: 'ck-table-form__border-width'
|
|
279
|
-
});
|
|
280
|
-
borderWidthInput.fieldView.bind('value').to(this, 'borderWidth');
|
|
281
|
-
borderWidthInput.bind('isEnabled').to(this, 'borderStyle', isBorderStyleSet);
|
|
282
|
-
borderWidthInput.fieldView.on('input', () => {
|
|
283
|
-
this.borderWidth = borderWidthInput.fieldView.element.value;
|
|
284
|
-
});
|
|
285
|
-
// -- Color ---------------------------------------------------
|
|
286
|
-
const borderColorInput = new LabeledFieldView(locale, colorInputCreator);
|
|
287
|
-
borderColorInput.set({
|
|
288
|
-
label: t('Color'),
|
|
289
|
-
class: 'ck-table-form__border-color'
|
|
290
|
-
});
|
|
291
|
-
borderColorInput.fieldView.bind('value').to(this, 'borderColor');
|
|
292
|
-
borderColorInput.bind('isEnabled').to(this, 'borderStyle', isBorderStyleSet);
|
|
293
|
-
borderColorInput.fieldView.on('input', () => {
|
|
294
|
-
this.borderColor = borderColorInput.fieldView.value;
|
|
295
|
-
});
|
|
296
|
-
// Reset the border color and width fields depending on the `border-style` value.
|
|
297
|
-
this.on('change:borderStyle', (evt, name, newValue, oldValue) => {
|
|
298
|
-
// When removing the border (`border-style:none`), clear the remaining `border-*` properties.
|
|
299
|
-
// See: https://github.com/ckeditor/ckeditor5/issues/6227.
|
|
300
|
-
if (!isBorderStyleSet(newValue)) {
|
|
301
|
-
this.borderColor = '';
|
|
302
|
-
this.borderWidth = '';
|
|
303
|
-
}
|
|
304
|
-
// When setting the `border-style` from `none`, set the default `border-color` and `border-width` properties.
|
|
305
|
-
if (!isBorderStyleSet(oldValue)) {
|
|
306
|
-
this.borderColor = defaultBorder.color;
|
|
307
|
-
this.borderWidth = defaultBorder.width;
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
return {
|
|
311
|
-
borderRowLabel,
|
|
312
|
-
borderStyleDropdown,
|
|
313
|
-
borderColorInput,
|
|
314
|
-
borderWidthInput
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Creates the following form fields:
|
|
319
|
-
*
|
|
320
|
-
* * {@link #backgroundInput}.
|
|
321
|
-
*/
|
|
322
|
-
_createBackgroundFields() {
|
|
323
|
-
const locale = this.locale;
|
|
324
|
-
const t = this.t;
|
|
325
|
-
// -- Group label ---------------------------------------------
|
|
326
|
-
const backgroundRowLabel = new LabelView(locale);
|
|
327
|
-
backgroundRowLabel.text = t('Background');
|
|
328
|
-
// -- Background color input -----------------------------------
|
|
329
|
-
const colorInputCreator = getLabeledColorInputCreator({
|
|
330
|
-
colorConfig: this.options.backgroundColors,
|
|
331
|
-
columns: 5,
|
|
332
|
-
defaultColorValue: this.options.defaultTableCellProperties.backgroundColor,
|
|
333
|
-
colorPickerConfig: this.options.colorPickerConfig
|
|
334
|
-
});
|
|
335
|
-
const backgroundInput = new LabeledFieldView(locale, colorInputCreator);
|
|
336
|
-
backgroundInput.set({
|
|
337
|
-
label: t('Color'),
|
|
338
|
-
class: 'ck-table-cell-properties-form__background'
|
|
339
|
-
});
|
|
340
|
-
backgroundInput.fieldView.bind('value').to(this, 'backgroundColor');
|
|
341
|
-
backgroundInput.fieldView.on('input', () => {
|
|
342
|
-
this.backgroundColor = backgroundInput.fieldView.value;
|
|
343
|
-
});
|
|
344
|
-
return {
|
|
345
|
-
backgroundRowLabel,
|
|
346
|
-
backgroundInput
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Creates the following form fields:
|
|
351
|
-
*
|
|
352
|
-
* * {@link #widthInput}.
|
|
353
|
-
* * {@link #heightInput}.
|
|
354
|
-
*/
|
|
355
|
-
_createDimensionFields() {
|
|
356
|
-
const locale = this.locale;
|
|
357
|
-
const t = this.t;
|
|
358
|
-
// -- Label ---------------------------------------------------
|
|
359
|
-
const dimensionsLabel = new LabelView(locale);
|
|
360
|
-
dimensionsLabel.text = t('Dimensions');
|
|
361
|
-
// -- Width ---------------------------------------------------
|
|
362
|
-
const widthInput = new LabeledFieldView(locale, createLabeledInputText);
|
|
363
|
-
widthInput.set({
|
|
364
|
-
label: t('Width'),
|
|
365
|
-
class: 'ck-table-form__dimensions-row__width'
|
|
366
|
-
});
|
|
367
|
-
widthInput.fieldView.bind('value').to(this, 'width');
|
|
368
|
-
widthInput.fieldView.on('input', () => {
|
|
369
|
-
this.width = widthInput.fieldView.element.value;
|
|
370
|
-
});
|
|
371
|
-
// -- Operator ---------------------------------------------------
|
|
372
|
-
const operatorLabel = new View(locale);
|
|
373
|
-
operatorLabel.setTemplate({
|
|
374
|
-
tag: 'span',
|
|
375
|
-
attributes: {
|
|
376
|
-
class: [
|
|
377
|
-
'ck-table-form__dimension-operator'
|
|
378
|
-
]
|
|
379
|
-
},
|
|
380
|
-
children: [
|
|
381
|
-
{ text: '×' }
|
|
382
|
-
]
|
|
383
|
-
});
|
|
384
|
-
// -- Height ---------------------------------------------------
|
|
385
|
-
const heightInput = new LabeledFieldView(locale, createLabeledInputText);
|
|
386
|
-
heightInput.set({
|
|
387
|
-
label: t('Height'),
|
|
388
|
-
class: 'ck-table-form__dimensions-row__height'
|
|
389
|
-
});
|
|
390
|
-
heightInput.fieldView.bind('value').to(this, 'height');
|
|
391
|
-
heightInput.fieldView.on('input', () => {
|
|
392
|
-
this.height = heightInput.fieldView.element.value;
|
|
393
|
-
});
|
|
394
|
-
return {
|
|
395
|
-
dimensionsLabel,
|
|
396
|
-
widthInput,
|
|
397
|
-
operatorLabel,
|
|
398
|
-
heightInput
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Creates the following form fields:
|
|
403
|
-
*
|
|
404
|
-
* * {@link #paddingInput}.
|
|
405
|
-
*/
|
|
406
|
-
_createPaddingField() {
|
|
407
|
-
const locale = this.locale;
|
|
408
|
-
const t = this.t;
|
|
409
|
-
const paddingInput = new LabeledFieldView(locale, createLabeledInputText);
|
|
410
|
-
paddingInput.set({
|
|
411
|
-
label: t('Padding'),
|
|
412
|
-
class: 'ck-table-cell-properties-form__padding'
|
|
413
|
-
});
|
|
414
|
-
paddingInput.fieldView.bind('value').to(this, 'padding');
|
|
415
|
-
paddingInput.fieldView.on('input', () => {
|
|
416
|
-
this.padding = paddingInput.fieldView.element.value;
|
|
417
|
-
});
|
|
418
|
-
return paddingInput;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Creates the following form fields:
|
|
422
|
-
*
|
|
423
|
-
* * {@link #horizontalAlignmentToolbar},
|
|
424
|
-
* * {@link #verticalAlignmentToolbar}.
|
|
425
|
-
*/
|
|
426
|
-
_createAlignmentFields() {
|
|
427
|
-
const locale = this.locale;
|
|
428
|
-
const t = this.t;
|
|
429
|
-
const alignmentLabel = new LabelView(locale);
|
|
430
|
-
alignmentLabel.text = t('Table cell text alignment');
|
|
431
|
-
// -- Horizontal ---------------------------------------------------
|
|
432
|
-
const horizontalAlignmentToolbar = new ToolbarView(locale);
|
|
433
|
-
const isContentRTL = locale.contentLanguageDirection === 'rtl';
|
|
434
|
-
horizontalAlignmentToolbar.set({
|
|
435
|
-
isCompact: true,
|
|
436
|
-
ariaLabel: t('Horizontal text alignment toolbar')
|
|
437
|
-
});
|
|
438
|
-
fillToolbar({
|
|
439
|
-
view: this,
|
|
440
|
-
icons: ALIGNMENT_ICONS,
|
|
441
|
-
toolbar: horizontalAlignmentToolbar,
|
|
442
|
-
labels: this._horizontalAlignmentLabels,
|
|
443
|
-
propertyName: 'horizontalAlignment',
|
|
444
|
-
nameToValue: name => {
|
|
445
|
-
// For the RTL content, we want to swap the buttons "align to the left" and "align to the right".
|
|
446
|
-
if (isContentRTL) {
|
|
447
|
-
if (name === 'left') {
|
|
448
|
-
return 'right';
|
|
449
|
-
}
|
|
450
|
-
else if (name === 'right') {
|
|
451
|
-
return 'left';
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
return name;
|
|
455
|
-
},
|
|
456
|
-
defaultValue: this.options.defaultTableCellProperties.horizontalAlignment
|
|
457
|
-
});
|
|
458
|
-
// -- Vertical -----------------------------------------------------
|
|
459
|
-
const verticalAlignmentToolbar = new ToolbarView(locale);
|
|
460
|
-
verticalAlignmentToolbar.set({
|
|
461
|
-
isCompact: true,
|
|
462
|
-
ariaLabel: t('Vertical text alignment toolbar')
|
|
463
|
-
});
|
|
464
|
-
fillToolbar({
|
|
465
|
-
view: this,
|
|
466
|
-
icons: ALIGNMENT_ICONS,
|
|
467
|
-
toolbar: verticalAlignmentToolbar,
|
|
468
|
-
labels: this._verticalAlignmentLabels,
|
|
469
|
-
propertyName: 'verticalAlignment',
|
|
470
|
-
defaultValue: this.options.defaultTableCellProperties.verticalAlignment
|
|
471
|
-
});
|
|
472
|
-
return {
|
|
473
|
-
horizontalAlignmentToolbar,
|
|
474
|
-
verticalAlignmentToolbar,
|
|
475
|
-
alignmentLabel
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Creates the following form controls:
|
|
480
|
-
*
|
|
481
|
-
* * {@link #saveButtonView},
|
|
482
|
-
* * {@link #cancelButtonView}.
|
|
483
|
-
*/
|
|
484
|
-
_createActionButtons() {
|
|
485
|
-
const locale = this.locale;
|
|
486
|
-
const t = this.t;
|
|
487
|
-
const saveButtonView = new ButtonView(locale);
|
|
488
|
-
const cancelButtonView = new ButtonView(locale);
|
|
489
|
-
const fieldsThatShouldValidateToSave = [
|
|
490
|
-
this.borderWidthInput,
|
|
491
|
-
this.borderColorInput,
|
|
492
|
-
this.backgroundInput,
|
|
493
|
-
this.paddingInput
|
|
494
|
-
];
|
|
495
|
-
saveButtonView.set({
|
|
496
|
-
label: t('Save'),
|
|
497
|
-
icon: icons.check,
|
|
498
|
-
class: 'ck-button-save',
|
|
499
|
-
type: 'submit',
|
|
500
|
-
withText: true
|
|
501
|
-
});
|
|
502
|
-
saveButtonView.bind('isEnabled').toMany(fieldsThatShouldValidateToSave, 'errorText', (...errorTexts) => {
|
|
503
|
-
return errorTexts.every(errorText => !errorText);
|
|
504
|
-
});
|
|
505
|
-
cancelButtonView.set({
|
|
506
|
-
label: t('Cancel'),
|
|
507
|
-
icon: icons.cancel,
|
|
508
|
-
class: 'ck-button-cancel',
|
|
509
|
-
withText: true
|
|
510
|
-
});
|
|
511
|
-
cancelButtonView.delegate('execute').to(this, 'cancel');
|
|
512
|
-
return {
|
|
513
|
-
saveButtonView, cancelButtonView
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Provides localized labels for {@link #horizontalAlignmentToolbar} buttons.
|
|
518
|
-
*/
|
|
519
|
-
get _horizontalAlignmentLabels() {
|
|
520
|
-
const locale = this.locale;
|
|
521
|
-
const t = this.t;
|
|
522
|
-
const left = t('Align cell text to the left');
|
|
523
|
-
const center = t('Align cell text to the center');
|
|
524
|
-
const right = t('Align cell text to the right');
|
|
525
|
-
const justify = t('Justify cell text');
|
|
526
|
-
// Returns object with a proper order of labels.
|
|
527
|
-
if (locale.uiLanguageDirection === 'rtl') {
|
|
528
|
-
return { right, center, left, justify };
|
|
529
|
-
}
|
|
530
|
-
else {
|
|
531
|
-
return { left, center, right, justify };
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Provides localized labels for {@link #verticalAlignmentToolbar} buttons.
|
|
536
|
-
*/
|
|
537
|
-
get _verticalAlignmentLabels() {
|
|
538
|
-
const t = this.t;
|
|
539
|
-
return {
|
|
540
|
-
top: t('Align cell text to the top'),
|
|
541
|
-
middle: t('Align cell text to the middle'),
|
|
542
|
-
bottom: t('Align cell text to the bottom')
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
function isBorderStyleSet(value) {
|
|
547
|
-
return value !== 'none';
|
|
548
|
-
}
|
|
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
|
+
// Maintain continuous focus cycling over views that have focusable children and focus cyclers themselves.
|
|
178
|
+
[this.borderColorInput, this.backgroundInput].forEach(view => {
|
|
179
|
+
view.fieldView.focusCycler.on('forwardCycle', evt => {
|
|
180
|
+
this._focusCycler.focusNext();
|
|
181
|
+
evt.stop();
|
|
182
|
+
});
|
|
183
|
+
view.fieldView.focusCycler.on('backwardCycle', evt => {
|
|
184
|
+
this._focusCycler.focusPrevious();
|
|
185
|
+
evt.stop();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
[
|
|
189
|
+
this.borderStyleDropdown,
|
|
190
|
+
this.borderColorInput,
|
|
191
|
+
this.borderWidthInput,
|
|
192
|
+
this.backgroundInput,
|
|
193
|
+
this.widthInput,
|
|
194
|
+
this.heightInput,
|
|
195
|
+
this.paddingInput,
|
|
196
|
+
this.horizontalAlignmentToolbar,
|
|
197
|
+
this.verticalAlignmentToolbar,
|
|
198
|
+
this.saveButtonView,
|
|
199
|
+
this.cancelButtonView
|
|
200
|
+
].forEach(view => {
|
|
201
|
+
// Register the view as focusable.
|
|
202
|
+
this._focusables.add(view);
|
|
203
|
+
// Register the view in the focus tracker.
|
|
204
|
+
this.focusTracker.add(view.element);
|
|
205
|
+
});
|
|
206
|
+
// Mainly for closing using "Esc" and navigation using "Tab".
|
|
207
|
+
this.keystrokes.listenTo(this.element);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @inheritDoc
|
|
211
|
+
*/
|
|
212
|
+
destroy() {
|
|
213
|
+
super.destroy();
|
|
214
|
+
this.focusTracker.destroy();
|
|
215
|
+
this.keystrokes.destroy();
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Focuses the fist focusable field in the form.
|
|
219
|
+
*/
|
|
220
|
+
focus() {
|
|
221
|
+
this._focusCycler.focusFirst();
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Creates the following form fields:
|
|
225
|
+
*
|
|
226
|
+
* * {@link #borderStyleDropdown},
|
|
227
|
+
* * {@link #borderWidthInput},
|
|
228
|
+
* * {@link #borderColorInput}.
|
|
229
|
+
*/
|
|
230
|
+
_createBorderFields() {
|
|
231
|
+
const defaultTableCellProperties = this.options.defaultTableCellProperties;
|
|
232
|
+
const defaultBorder = {
|
|
233
|
+
style: defaultTableCellProperties.borderStyle,
|
|
234
|
+
width: defaultTableCellProperties.borderWidth,
|
|
235
|
+
color: defaultTableCellProperties.borderColor
|
|
236
|
+
};
|
|
237
|
+
const colorInputCreator = getLabeledColorInputCreator({
|
|
238
|
+
colorConfig: this.options.borderColors,
|
|
239
|
+
columns: 5,
|
|
240
|
+
defaultColorValue: defaultBorder.color,
|
|
241
|
+
colorPickerConfig: this.options.colorPickerConfig
|
|
242
|
+
});
|
|
243
|
+
const locale = this.locale;
|
|
244
|
+
const t = this.t;
|
|
245
|
+
const accessibleLabel = t('Style');
|
|
246
|
+
// -- Group label ---------------------------------------------
|
|
247
|
+
const borderRowLabel = new LabelView(locale);
|
|
248
|
+
borderRowLabel.text = t('Border');
|
|
249
|
+
// -- Style ---------------------------------------------------
|
|
250
|
+
const styleLabels = getBorderStyleLabels(t);
|
|
251
|
+
const borderStyleDropdown = new LabeledFieldView(locale, createLabeledDropdown);
|
|
252
|
+
borderStyleDropdown.set({
|
|
253
|
+
label: accessibleLabel,
|
|
254
|
+
class: 'ck-table-form__border-style'
|
|
255
|
+
});
|
|
256
|
+
borderStyleDropdown.fieldView.buttonView.set({
|
|
257
|
+
ariaLabel: accessibleLabel,
|
|
258
|
+
ariaLabelledBy: undefined,
|
|
259
|
+
isOn: false,
|
|
260
|
+
withText: true,
|
|
261
|
+
tooltip: accessibleLabel
|
|
262
|
+
});
|
|
263
|
+
borderStyleDropdown.fieldView.buttonView.bind('label').to(this, 'borderStyle', value => {
|
|
264
|
+
return styleLabels[value ? value : 'none'];
|
|
265
|
+
});
|
|
266
|
+
borderStyleDropdown.fieldView.on('execute', evt => {
|
|
267
|
+
this.borderStyle = evt.source._borderStyleValue;
|
|
268
|
+
});
|
|
269
|
+
borderStyleDropdown.bind('isEmpty').to(this, 'borderStyle', value => !value);
|
|
270
|
+
addListToDropdown(borderStyleDropdown.fieldView, getBorderStyleDefinitions(this, defaultBorder.style), {
|
|
271
|
+
role: 'menu',
|
|
272
|
+
ariaLabel: accessibleLabel
|
|
273
|
+
});
|
|
274
|
+
// -- Width ---------------------------------------------------
|
|
275
|
+
const borderWidthInput = new LabeledFieldView(locale, createLabeledInputText);
|
|
276
|
+
borderWidthInput.set({
|
|
277
|
+
label: t('Width'),
|
|
278
|
+
class: 'ck-table-form__border-width'
|
|
279
|
+
});
|
|
280
|
+
borderWidthInput.fieldView.bind('value').to(this, 'borderWidth');
|
|
281
|
+
borderWidthInput.bind('isEnabled').to(this, 'borderStyle', isBorderStyleSet);
|
|
282
|
+
borderWidthInput.fieldView.on('input', () => {
|
|
283
|
+
this.borderWidth = borderWidthInput.fieldView.element.value;
|
|
284
|
+
});
|
|
285
|
+
// -- Color ---------------------------------------------------
|
|
286
|
+
const borderColorInput = new LabeledFieldView(locale, colorInputCreator);
|
|
287
|
+
borderColorInput.set({
|
|
288
|
+
label: t('Color'),
|
|
289
|
+
class: 'ck-table-form__border-color'
|
|
290
|
+
});
|
|
291
|
+
borderColorInput.fieldView.bind('value').to(this, 'borderColor');
|
|
292
|
+
borderColorInput.bind('isEnabled').to(this, 'borderStyle', isBorderStyleSet);
|
|
293
|
+
borderColorInput.fieldView.on('input', () => {
|
|
294
|
+
this.borderColor = borderColorInput.fieldView.value;
|
|
295
|
+
});
|
|
296
|
+
// Reset the border color and width fields depending on the `border-style` value.
|
|
297
|
+
this.on('change:borderStyle', (evt, name, newValue, oldValue) => {
|
|
298
|
+
// When removing the border (`border-style:none`), clear the remaining `border-*` properties.
|
|
299
|
+
// See: https://github.com/ckeditor/ckeditor5/issues/6227.
|
|
300
|
+
if (!isBorderStyleSet(newValue)) {
|
|
301
|
+
this.borderColor = '';
|
|
302
|
+
this.borderWidth = '';
|
|
303
|
+
}
|
|
304
|
+
// When setting the `border-style` from `none`, set the default `border-color` and `border-width` properties.
|
|
305
|
+
if (!isBorderStyleSet(oldValue)) {
|
|
306
|
+
this.borderColor = defaultBorder.color;
|
|
307
|
+
this.borderWidth = defaultBorder.width;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
return {
|
|
311
|
+
borderRowLabel,
|
|
312
|
+
borderStyleDropdown,
|
|
313
|
+
borderColorInput,
|
|
314
|
+
borderWidthInput
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Creates the following form fields:
|
|
319
|
+
*
|
|
320
|
+
* * {@link #backgroundInput}.
|
|
321
|
+
*/
|
|
322
|
+
_createBackgroundFields() {
|
|
323
|
+
const locale = this.locale;
|
|
324
|
+
const t = this.t;
|
|
325
|
+
// -- Group label ---------------------------------------------
|
|
326
|
+
const backgroundRowLabel = new LabelView(locale);
|
|
327
|
+
backgroundRowLabel.text = t('Background');
|
|
328
|
+
// -- Background color input -----------------------------------
|
|
329
|
+
const colorInputCreator = getLabeledColorInputCreator({
|
|
330
|
+
colorConfig: this.options.backgroundColors,
|
|
331
|
+
columns: 5,
|
|
332
|
+
defaultColorValue: this.options.defaultTableCellProperties.backgroundColor,
|
|
333
|
+
colorPickerConfig: this.options.colorPickerConfig
|
|
334
|
+
});
|
|
335
|
+
const backgroundInput = new LabeledFieldView(locale, colorInputCreator);
|
|
336
|
+
backgroundInput.set({
|
|
337
|
+
label: t('Color'),
|
|
338
|
+
class: 'ck-table-cell-properties-form__background'
|
|
339
|
+
});
|
|
340
|
+
backgroundInput.fieldView.bind('value').to(this, 'backgroundColor');
|
|
341
|
+
backgroundInput.fieldView.on('input', () => {
|
|
342
|
+
this.backgroundColor = backgroundInput.fieldView.value;
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
backgroundRowLabel,
|
|
346
|
+
backgroundInput
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Creates the following form fields:
|
|
351
|
+
*
|
|
352
|
+
* * {@link #widthInput}.
|
|
353
|
+
* * {@link #heightInput}.
|
|
354
|
+
*/
|
|
355
|
+
_createDimensionFields() {
|
|
356
|
+
const locale = this.locale;
|
|
357
|
+
const t = this.t;
|
|
358
|
+
// -- Label ---------------------------------------------------
|
|
359
|
+
const dimensionsLabel = new LabelView(locale);
|
|
360
|
+
dimensionsLabel.text = t('Dimensions');
|
|
361
|
+
// -- Width ---------------------------------------------------
|
|
362
|
+
const widthInput = new LabeledFieldView(locale, createLabeledInputText);
|
|
363
|
+
widthInput.set({
|
|
364
|
+
label: t('Width'),
|
|
365
|
+
class: 'ck-table-form__dimensions-row__width'
|
|
366
|
+
});
|
|
367
|
+
widthInput.fieldView.bind('value').to(this, 'width');
|
|
368
|
+
widthInput.fieldView.on('input', () => {
|
|
369
|
+
this.width = widthInput.fieldView.element.value;
|
|
370
|
+
});
|
|
371
|
+
// -- Operator ---------------------------------------------------
|
|
372
|
+
const operatorLabel = new View(locale);
|
|
373
|
+
operatorLabel.setTemplate({
|
|
374
|
+
tag: 'span',
|
|
375
|
+
attributes: {
|
|
376
|
+
class: [
|
|
377
|
+
'ck-table-form__dimension-operator'
|
|
378
|
+
]
|
|
379
|
+
},
|
|
380
|
+
children: [
|
|
381
|
+
{ text: '×' }
|
|
382
|
+
]
|
|
383
|
+
});
|
|
384
|
+
// -- Height ---------------------------------------------------
|
|
385
|
+
const heightInput = new LabeledFieldView(locale, createLabeledInputText);
|
|
386
|
+
heightInput.set({
|
|
387
|
+
label: t('Height'),
|
|
388
|
+
class: 'ck-table-form__dimensions-row__height'
|
|
389
|
+
});
|
|
390
|
+
heightInput.fieldView.bind('value').to(this, 'height');
|
|
391
|
+
heightInput.fieldView.on('input', () => {
|
|
392
|
+
this.height = heightInput.fieldView.element.value;
|
|
393
|
+
});
|
|
394
|
+
return {
|
|
395
|
+
dimensionsLabel,
|
|
396
|
+
widthInput,
|
|
397
|
+
operatorLabel,
|
|
398
|
+
heightInput
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Creates the following form fields:
|
|
403
|
+
*
|
|
404
|
+
* * {@link #paddingInput}.
|
|
405
|
+
*/
|
|
406
|
+
_createPaddingField() {
|
|
407
|
+
const locale = this.locale;
|
|
408
|
+
const t = this.t;
|
|
409
|
+
const paddingInput = new LabeledFieldView(locale, createLabeledInputText);
|
|
410
|
+
paddingInput.set({
|
|
411
|
+
label: t('Padding'),
|
|
412
|
+
class: 'ck-table-cell-properties-form__padding'
|
|
413
|
+
});
|
|
414
|
+
paddingInput.fieldView.bind('value').to(this, 'padding');
|
|
415
|
+
paddingInput.fieldView.on('input', () => {
|
|
416
|
+
this.padding = paddingInput.fieldView.element.value;
|
|
417
|
+
});
|
|
418
|
+
return paddingInput;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Creates the following form fields:
|
|
422
|
+
*
|
|
423
|
+
* * {@link #horizontalAlignmentToolbar},
|
|
424
|
+
* * {@link #verticalAlignmentToolbar}.
|
|
425
|
+
*/
|
|
426
|
+
_createAlignmentFields() {
|
|
427
|
+
const locale = this.locale;
|
|
428
|
+
const t = this.t;
|
|
429
|
+
const alignmentLabel = new LabelView(locale);
|
|
430
|
+
alignmentLabel.text = t('Table cell text alignment');
|
|
431
|
+
// -- Horizontal ---------------------------------------------------
|
|
432
|
+
const horizontalAlignmentToolbar = new ToolbarView(locale);
|
|
433
|
+
const isContentRTL = locale.contentLanguageDirection === 'rtl';
|
|
434
|
+
horizontalAlignmentToolbar.set({
|
|
435
|
+
isCompact: true,
|
|
436
|
+
ariaLabel: t('Horizontal text alignment toolbar')
|
|
437
|
+
});
|
|
438
|
+
fillToolbar({
|
|
439
|
+
view: this,
|
|
440
|
+
icons: ALIGNMENT_ICONS,
|
|
441
|
+
toolbar: horizontalAlignmentToolbar,
|
|
442
|
+
labels: this._horizontalAlignmentLabels,
|
|
443
|
+
propertyName: 'horizontalAlignment',
|
|
444
|
+
nameToValue: name => {
|
|
445
|
+
// For the RTL content, we want to swap the buttons "align to the left" and "align to the right".
|
|
446
|
+
if (isContentRTL) {
|
|
447
|
+
if (name === 'left') {
|
|
448
|
+
return 'right';
|
|
449
|
+
}
|
|
450
|
+
else if (name === 'right') {
|
|
451
|
+
return 'left';
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return name;
|
|
455
|
+
},
|
|
456
|
+
defaultValue: this.options.defaultTableCellProperties.horizontalAlignment
|
|
457
|
+
});
|
|
458
|
+
// -- Vertical -----------------------------------------------------
|
|
459
|
+
const verticalAlignmentToolbar = new ToolbarView(locale);
|
|
460
|
+
verticalAlignmentToolbar.set({
|
|
461
|
+
isCompact: true,
|
|
462
|
+
ariaLabel: t('Vertical text alignment toolbar')
|
|
463
|
+
});
|
|
464
|
+
fillToolbar({
|
|
465
|
+
view: this,
|
|
466
|
+
icons: ALIGNMENT_ICONS,
|
|
467
|
+
toolbar: verticalAlignmentToolbar,
|
|
468
|
+
labels: this._verticalAlignmentLabels,
|
|
469
|
+
propertyName: 'verticalAlignment',
|
|
470
|
+
defaultValue: this.options.defaultTableCellProperties.verticalAlignment
|
|
471
|
+
});
|
|
472
|
+
return {
|
|
473
|
+
horizontalAlignmentToolbar,
|
|
474
|
+
verticalAlignmentToolbar,
|
|
475
|
+
alignmentLabel
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Creates the following form controls:
|
|
480
|
+
*
|
|
481
|
+
* * {@link #saveButtonView},
|
|
482
|
+
* * {@link #cancelButtonView}.
|
|
483
|
+
*/
|
|
484
|
+
_createActionButtons() {
|
|
485
|
+
const locale = this.locale;
|
|
486
|
+
const t = this.t;
|
|
487
|
+
const saveButtonView = new ButtonView(locale);
|
|
488
|
+
const cancelButtonView = new ButtonView(locale);
|
|
489
|
+
const fieldsThatShouldValidateToSave = [
|
|
490
|
+
this.borderWidthInput,
|
|
491
|
+
this.borderColorInput,
|
|
492
|
+
this.backgroundInput,
|
|
493
|
+
this.paddingInput
|
|
494
|
+
];
|
|
495
|
+
saveButtonView.set({
|
|
496
|
+
label: t('Save'),
|
|
497
|
+
icon: icons.check,
|
|
498
|
+
class: 'ck-button-save',
|
|
499
|
+
type: 'submit',
|
|
500
|
+
withText: true
|
|
501
|
+
});
|
|
502
|
+
saveButtonView.bind('isEnabled').toMany(fieldsThatShouldValidateToSave, 'errorText', (...errorTexts) => {
|
|
503
|
+
return errorTexts.every(errorText => !errorText);
|
|
504
|
+
});
|
|
505
|
+
cancelButtonView.set({
|
|
506
|
+
label: t('Cancel'),
|
|
507
|
+
icon: icons.cancel,
|
|
508
|
+
class: 'ck-button-cancel',
|
|
509
|
+
withText: true
|
|
510
|
+
});
|
|
511
|
+
cancelButtonView.delegate('execute').to(this, 'cancel');
|
|
512
|
+
return {
|
|
513
|
+
saveButtonView, cancelButtonView
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Provides localized labels for {@link #horizontalAlignmentToolbar} buttons.
|
|
518
|
+
*/
|
|
519
|
+
get _horizontalAlignmentLabels() {
|
|
520
|
+
const locale = this.locale;
|
|
521
|
+
const t = this.t;
|
|
522
|
+
const left = t('Align cell text to the left');
|
|
523
|
+
const center = t('Align cell text to the center');
|
|
524
|
+
const right = t('Align cell text to the right');
|
|
525
|
+
const justify = t('Justify cell text');
|
|
526
|
+
// Returns object with a proper order of labels.
|
|
527
|
+
if (locale.uiLanguageDirection === 'rtl') {
|
|
528
|
+
return { right, center, left, justify };
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
return { left, center, right, justify };
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Provides localized labels for {@link #verticalAlignmentToolbar} buttons.
|
|
536
|
+
*/
|
|
537
|
+
get _verticalAlignmentLabels() {
|
|
538
|
+
const t = this.t;
|
|
539
|
+
return {
|
|
540
|
+
top: t('Align cell text to the top'),
|
|
541
|
+
middle: t('Align cell text to the middle'),
|
|
542
|
+
bottom: t('Align cell text to the bottom')
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function isBorderStyleSet(value) {
|
|
547
|
+
return value !== 'none';
|
|
548
|
+
}
|