@ckeditor/ckeditor5-font 36.0.0 → 37.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/font.js +1 -1
- package/package.json +20 -15
- package/src/documentcolorcollection.d.ts +47 -0
- package/src/documentcolorcollection.js +34 -63
- package/src/font.d.ts +34 -0
- package/src/font.js +12 -19
- package/src/fontbackgroundcolor/fontbackgroundcolorcommand.d.ts +32 -0
- package/src/fontbackgroundcolor/fontbackgroundcolorcommand.js +9 -15
- package/src/fontbackgroundcolor/fontbackgroundcolorediting.d.ts +31 -0
- package/src/fontbackgroundcolor/fontbackgroundcolorediting.js +102 -115
- package/src/fontbackgroundcolor/fontbackgroundcolorui.d.ts +27 -0
- package/src/fontbackgroundcolor/fontbackgroundcolorui.js +18 -25
- package/src/fontbackgroundcolor.d.ts +33 -0
- package/src/fontbackgroundcolor.js +12 -165
- package/src/fontcolor/fontcolorcommand.d.ts +31 -0
- package/src/fontcolor/fontcolorcommand.js +9 -15
- package/src/fontcolor/fontcolorediting.d.ts +31 -0
- package/src/fontcolor/fontcolorediting.js +115 -128
- package/src/fontcolor/fontcolorui.d.ts +27 -0
- package/src/fontcolor/fontcolorui.js +18 -25
- package/src/fontcolor.d.ts +29 -0
- package/src/fontcolor.js +12 -168
- package/src/fontcommand.d.ts +46 -0
- package/src/fontcommand.js +54 -78
- package/src/fontconfig.d.ts +399 -0
- package/src/fontconfig.js +5 -0
- package/src/fontfamily/fontfamilycommand.d.ts +31 -0
- package/src/fontfamily/fontfamilycommand.js +9 -15
- package/src/fontfamily/fontfamilyediting.d.ts +45 -0
- package/src/fontfamily/fontfamilyediting.js +96 -116
- package/src/fontfamily/fontfamilyui.d.ts +35 -0
- package/src/fontfamily/fontfamilyui.js +90 -122
- package/src/fontfamily/utils.d.ts +15 -0
- package/src/fontfamily/utils.js +66 -79
- package/src/fontfamily.d.ts +29 -0
- package/src/fontfamily.js +12 -112
- package/src/fontsize/fontsizecommand.d.ts +31 -0
- package/src/fontsize/fontsizecommand.js +9 -15
- package/src/fontsize/fontsizeediting.d.ts +50 -0
- package/src/fontsize/fontsizeediting.js +138 -169
- package/src/fontsize/fontsizeui.d.ts +36 -0
- package/src/fontsize/fontsizeui.js +98 -130
- package/src/fontsize/utils.d.ts +12 -0
- package/src/fontsize/utils.js +145 -174
- package/src/fontsize.d.ts +40 -0
- package/src/fontsize.js +21 -141
- package/src/index.d.ts +20 -0
- package/src/index.js +0 -2
- package/src/ui/colortableview.d.ts +167 -0
- package/src/ui/colortableview.js +240 -416
- package/src/ui/colorui.d.ts +64 -0
- package/src/ui/colorui.js +79 -132
- package/src/utils.d.ts +77 -0
- package/src/utils.js +42 -72
package/src/ui/colortableview.js
CHANGED
|
@@ -2,435 +2,259 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module font/ui/colortableview
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { icons } from 'ckeditor5/src/core';
|
|
11
|
-
import {
|
|
12
|
-
ButtonView,
|
|
13
|
-
ColorGridView,
|
|
14
|
-
ColorTileView,
|
|
15
|
-
FocusCycler,
|
|
16
|
-
LabelView,
|
|
17
|
-
Template,
|
|
18
|
-
View,
|
|
19
|
-
ViewCollection
|
|
20
|
-
} from 'ckeditor5/src/ui';
|
|
9
|
+
import { ButtonView, ColorGridView, ColorTileView, FocusCycler, LabelView, Template, View, ViewCollection } from 'ckeditor5/src/ui';
|
|
21
10
|
import { FocusTracker, KeystrokeHandler } from 'ckeditor5/src/utils';
|
|
22
|
-
|
|
23
11
|
import DocumentColorCollection from '../documentcolorcollection';
|
|
24
|
-
|
|
25
12
|
import '../../theme/fontcolor.css';
|
|
26
|
-
|
|
27
13
|
/**
|
|
28
14
|
* A class which represents a view with the following sub–components:
|
|
29
15
|
*
|
|
30
16
|
* * A remove color button,
|
|
31
17
|
* * A static {@link module:ui/colorgrid/colorgrid~ColorGridView} of colors defined in the configuration,
|
|
32
18
|
* * A dynamic {@link module:ui/colorgrid/colorgrid~ColorGridView} of colors used in the document.
|
|
33
|
-
*
|
|
34
|
-
* @extends module:ui/view~View
|
|
35
19
|
*/
|
|
36
20
|
export default class ColorTableView extends View {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
// Create a label for document colors.
|
|
277
|
-
const bind = Template.bind( this.documentColors, this.documentColors );
|
|
278
|
-
const label = new LabelView( this.locale );
|
|
279
|
-
label.text = this._documentColorsLabel;
|
|
280
|
-
label.extendTemplate( {
|
|
281
|
-
attributes: {
|
|
282
|
-
class: [
|
|
283
|
-
'ck',
|
|
284
|
-
'ck-color-grid__label',
|
|
285
|
-
bind.if( 'isEmpty', 'ck-hidden' )
|
|
286
|
-
]
|
|
287
|
-
}
|
|
288
|
-
} );
|
|
289
|
-
this.items.add( label );
|
|
290
|
-
this.documentColorsGrid = this._createDocumentColorsGrid();
|
|
291
|
-
|
|
292
|
-
this.items.add( this.documentColorsGrid );
|
|
293
|
-
this.focusTracker.add( this.documentColorsGrid.element );
|
|
294
|
-
this._focusables.add( this.documentColorsGrid );
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Focuses the first focusable element in {@link #items}.
|
|
300
|
-
*/
|
|
301
|
-
focus() {
|
|
302
|
-
this._focusCycler.focusFirst();
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Focuses the last focusable element in {@link #items}.
|
|
307
|
-
*/
|
|
308
|
-
focusLast() {
|
|
309
|
-
this._focusCycler.focusLast();
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Adds the remove color button as a child of the current view.
|
|
314
|
-
*
|
|
315
|
-
* @private
|
|
316
|
-
* @returns {module:ui/button/buttonview~ButtonView}
|
|
317
|
-
*/
|
|
318
|
-
_createRemoveColorButton() {
|
|
319
|
-
const buttonView = new ButtonView();
|
|
320
|
-
|
|
321
|
-
buttonView.set( {
|
|
322
|
-
withText: true,
|
|
323
|
-
icon: icons.eraser,
|
|
324
|
-
label: this.removeButtonLabel
|
|
325
|
-
} );
|
|
326
|
-
|
|
327
|
-
buttonView.class = 'ck-color-table__remove-color';
|
|
328
|
-
buttonView.on( 'execute', () => {
|
|
329
|
-
this.fire( 'execute', { value: null } );
|
|
330
|
-
} );
|
|
331
|
-
|
|
332
|
-
buttonView.render();
|
|
333
|
-
|
|
334
|
-
this.focusTracker.add( buttonView.element );
|
|
335
|
-
this._focusables.add( buttonView );
|
|
336
|
-
|
|
337
|
-
return buttonView;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Creates a static color table grid based on the editor configuration.
|
|
342
|
-
*
|
|
343
|
-
* @private
|
|
344
|
-
* @returns {module:ui/colorgrid/colorgrid~ColorGridView}
|
|
345
|
-
*/
|
|
346
|
-
_createStaticColorsGrid() {
|
|
347
|
-
const colorGrid = new ColorGridView( this.locale, {
|
|
348
|
-
colorDefinitions: this.colorDefinitions,
|
|
349
|
-
columns: this.columns
|
|
350
|
-
} );
|
|
351
|
-
|
|
352
|
-
colorGrid.delegate( 'execute' ).to( this );
|
|
353
|
-
|
|
354
|
-
return colorGrid;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Creates the document colors section view and binds it to {@link #documentColors}.
|
|
359
|
-
*
|
|
360
|
-
* @private
|
|
361
|
-
* @returns {module:ui/colorgrid/colorgrid~ColorGridView}
|
|
362
|
-
*/
|
|
363
|
-
_createDocumentColorsGrid() {
|
|
364
|
-
const bind = Template.bind( this.documentColors, this.documentColors );
|
|
365
|
-
const documentColorsGrid = new ColorGridView( this.locale, {
|
|
366
|
-
columns: this.columns
|
|
367
|
-
} );
|
|
368
|
-
|
|
369
|
-
documentColorsGrid.delegate( 'execute' ).to( this );
|
|
370
|
-
|
|
371
|
-
documentColorsGrid.extendTemplate( {
|
|
372
|
-
attributes: {
|
|
373
|
-
class: bind.if( 'isEmpty', 'ck-hidden' )
|
|
374
|
-
}
|
|
375
|
-
} );
|
|
376
|
-
|
|
377
|
-
documentColorsGrid.items.bindTo( this.documentColors ).using(
|
|
378
|
-
colorObj => {
|
|
379
|
-
const colorTile = new ColorTileView();
|
|
380
|
-
|
|
381
|
-
colorTile.set( {
|
|
382
|
-
color: colorObj.color,
|
|
383
|
-
hasBorder: colorObj.options && colorObj.options.hasBorder
|
|
384
|
-
} );
|
|
385
|
-
|
|
386
|
-
if ( colorObj.label ) {
|
|
387
|
-
colorTile.set( {
|
|
388
|
-
label: colorObj.label,
|
|
389
|
-
tooltip: true
|
|
390
|
-
} );
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
colorTile.on( 'execute', () => {
|
|
394
|
-
this.fire( 'execute', {
|
|
395
|
-
value: colorObj.color
|
|
396
|
-
} );
|
|
397
|
-
} );
|
|
398
|
-
|
|
399
|
-
return colorTile;
|
|
400
|
-
}
|
|
401
|
-
);
|
|
402
|
-
|
|
403
|
-
// Selected color should be cleared when document colors became empty.
|
|
404
|
-
this.documentColors.on( 'change:isEmpty', ( evt, name, val ) => {
|
|
405
|
-
if ( val ) {
|
|
406
|
-
documentColorsGrid.selectedColor = null;
|
|
407
|
-
}
|
|
408
|
-
} );
|
|
409
|
-
|
|
410
|
-
return documentColorsGrid;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Adds a given color to the document colors list. If possible, the method will attempt to use
|
|
415
|
-
* data from the {@link #colorDefinitions} (label, color options).
|
|
416
|
-
*
|
|
417
|
-
* @private
|
|
418
|
-
* @param {String} color A string that stores the value of the recently applied color.
|
|
419
|
-
*/
|
|
420
|
-
_addColorToDocumentColors( color ) {
|
|
421
|
-
const predefinedColor = this.colorDefinitions
|
|
422
|
-
.find( definition => definition.color === color );
|
|
423
|
-
|
|
424
|
-
if ( !predefinedColor ) {
|
|
425
|
-
this.documentColors.add( {
|
|
426
|
-
color,
|
|
427
|
-
label: color,
|
|
428
|
-
options: {
|
|
429
|
-
hasBorder: false
|
|
430
|
-
}
|
|
431
|
-
} );
|
|
432
|
-
} else {
|
|
433
|
-
this.documentColors.add( Object.assign( {}, predefinedColor ) );
|
|
434
|
-
}
|
|
435
|
-
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a view to be inserted as a child of {@link module:ui/dropdown/dropdownview~DropdownView}.
|
|
23
|
+
*
|
|
24
|
+
* @param locale The localization services instance.
|
|
25
|
+
* @param colors An array with definitions of colors to be displayed in the table.
|
|
26
|
+
* @param columns The number of columns in the color grid.
|
|
27
|
+
* @param removeButtonLabel The label of the button responsible for removing the color.
|
|
28
|
+
* @param documentColorsLabel The label for the section with the document colors.
|
|
29
|
+
* @param documentColorsCount The number of colors in the document colors section inside the color dropdown.
|
|
30
|
+
*/
|
|
31
|
+
constructor(locale, { colors, columns, removeButtonLabel, documentColorsLabel, documentColorsCount }) {
|
|
32
|
+
super(locale);
|
|
33
|
+
this.items = this.createCollection();
|
|
34
|
+
this.colorDefinitions = colors;
|
|
35
|
+
this.focusTracker = new FocusTracker();
|
|
36
|
+
this.keystrokes = new KeystrokeHandler();
|
|
37
|
+
this.set('selectedColor', undefined);
|
|
38
|
+
this.removeButtonLabel = removeButtonLabel;
|
|
39
|
+
this.columns = columns;
|
|
40
|
+
this.documentColors = new DocumentColorCollection();
|
|
41
|
+
this.documentColorsCount = documentColorsCount;
|
|
42
|
+
this._focusables = new ViewCollection();
|
|
43
|
+
this._focusCycler = new FocusCycler({
|
|
44
|
+
focusables: this._focusables,
|
|
45
|
+
focusTracker: this.focusTracker,
|
|
46
|
+
keystrokeHandler: this.keystrokes,
|
|
47
|
+
actions: {
|
|
48
|
+
// Navigate list items backwards using the <kbd>Shift</kbd> + <kbd>Tab</kbd> keystroke.
|
|
49
|
+
focusPrevious: 'shift + tab',
|
|
50
|
+
// Navigate list items forwards using the <kbd>Tab</kbd> key.
|
|
51
|
+
focusNext: 'tab'
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
this._documentColorsLabel = documentColorsLabel;
|
|
55
|
+
this.setTemplate({
|
|
56
|
+
tag: 'div',
|
|
57
|
+
attributes: {
|
|
58
|
+
class: [
|
|
59
|
+
'ck',
|
|
60
|
+
'ck-color-table'
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
children: this.items
|
|
64
|
+
});
|
|
65
|
+
this.items.add(this._createRemoveColorButton());
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Scans through the editor model and searches for text node attributes with the given attribute name.
|
|
69
|
+
* Found entries are set as document colors.
|
|
70
|
+
*
|
|
71
|
+
* All the previously stored document colors will be lost in the process.
|
|
72
|
+
*
|
|
73
|
+
* @param model The model used as a source to obtain the document colors.
|
|
74
|
+
* @param attributeName Determines the name of the related model's attribute for a given dropdown.
|
|
75
|
+
*/
|
|
76
|
+
updateDocumentColors(model, attributeName) {
|
|
77
|
+
const document = model.document;
|
|
78
|
+
const maxCount = this.documentColorsCount;
|
|
79
|
+
this.documentColors.clear();
|
|
80
|
+
for (const rootName of document.getRootNames()) {
|
|
81
|
+
const root = document.getRoot(rootName);
|
|
82
|
+
const range = model.createRangeIn(root);
|
|
83
|
+
for (const node of range.getItems()) {
|
|
84
|
+
if (node.is('$textProxy') && node.hasAttribute(attributeName)) {
|
|
85
|
+
this._addColorToDocumentColors(node.getAttribute(attributeName));
|
|
86
|
+
if (this.documentColors.length >= maxCount) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Refreshes the state of the selected color in one or both {@link module:ui/colorgrid/colorgrid~ColorGridView}s
|
|
95
|
+
* available in the {@link module:font/ui/colortableview~ColorTableView}. It guarantees that the selection will occur only in one
|
|
96
|
+
* of them.
|
|
97
|
+
*/
|
|
98
|
+
updateSelectedColors() {
|
|
99
|
+
const documentColorsGrid = this.documentColorsGrid;
|
|
100
|
+
const staticColorsGrid = this.staticColorsGrid;
|
|
101
|
+
const selectedColor = this.selectedColor;
|
|
102
|
+
staticColorsGrid.selectedColor = selectedColor;
|
|
103
|
+
if (documentColorsGrid) {
|
|
104
|
+
documentColorsGrid.selectedColor = selectedColor;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @inheritDoc
|
|
109
|
+
*/
|
|
110
|
+
render() {
|
|
111
|
+
super.render();
|
|
112
|
+
// Start listening for the keystrokes coming from #element.
|
|
113
|
+
this.keystrokes.listenTo(this.element);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @inheritDoc
|
|
117
|
+
*/
|
|
118
|
+
destroy() {
|
|
119
|
+
super.destroy();
|
|
120
|
+
this.focusTracker.destroy();
|
|
121
|
+
this.keystrokes.destroy();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Appends {@link #staticColorsGrid} and {@link #documentColorsGrid} views.
|
|
125
|
+
*/
|
|
126
|
+
appendGrids() {
|
|
127
|
+
if (this.staticColorsGrid) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.staticColorsGrid = this._createStaticColorsGrid();
|
|
131
|
+
this.items.add(this.staticColorsGrid);
|
|
132
|
+
this.focusTracker.add(this.staticColorsGrid.element);
|
|
133
|
+
this._focusables.add(this.staticColorsGrid);
|
|
134
|
+
if (this.documentColorsCount) {
|
|
135
|
+
// Create a label for document colors.
|
|
136
|
+
const bind = Template.bind(this.documentColors, this.documentColors);
|
|
137
|
+
const label = new LabelView(this.locale);
|
|
138
|
+
label.text = this._documentColorsLabel;
|
|
139
|
+
label.extendTemplate({
|
|
140
|
+
attributes: {
|
|
141
|
+
class: [
|
|
142
|
+
'ck',
|
|
143
|
+
'ck-color-grid__label',
|
|
144
|
+
bind.if('isEmpty', 'ck-hidden')
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
this.items.add(label);
|
|
149
|
+
this.documentColorsGrid = this._createDocumentColorsGrid();
|
|
150
|
+
this.items.add(this.documentColorsGrid);
|
|
151
|
+
this.focusTracker.add(this.documentColorsGrid.element);
|
|
152
|
+
this._focusables.add(this.documentColorsGrid);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Focuses the first focusable element in {@link #items}.
|
|
157
|
+
*/
|
|
158
|
+
focus() {
|
|
159
|
+
this._focusCycler.focusFirst();
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Focuses the last focusable element in {@link #items}.
|
|
163
|
+
*/
|
|
164
|
+
focusLast() {
|
|
165
|
+
this._focusCycler.focusLast();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Adds the remove color button as a child of the current view.
|
|
169
|
+
*/
|
|
170
|
+
_createRemoveColorButton() {
|
|
171
|
+
const buttonView = new ButtonView();
|
|
172
|
+
buttonView.set({
|
|
173
|
+
withText: true,
|
|
174
|
+
icon: icons.eraser,
|
|
175
|
+
label: this.removeButtonLabel
|
|
176
|
+
});
|
|
177
|
+
buttonView.class = 'ck-color-table__remove-color';
|
|
178
|
+
buttonView.on('execute', () => {
|
|
179
|
+
this.fire('execute', { value: null });
|
|
180
|
+
});
|
|
181
|
+
buttonView.render();
|
|
182
|
+
this.focusTracker.add(buttonView.element);
|
|
183
|
+
this._focusables.add(buttonView);
|
|
184
|
+
return buttonView;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Creates a static color table grid based on the editor configuration.
|
|
188
|
+
*/
|
|
189
|
+
_createStaticColorsGrid() {
|
|
190
|
+
const colorGrid = new ColorGridView(this.locale, {
|
|
191
|
+
colorDefinitions: this.colorDefinitions,
|
|
192
|
+
columns: this.columns
|
|
193
|
+
});
|
|
194
|
+
colorGrid.delegate('execute').to(this);
|
|
195
|
+
return colorGrid;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Creates the document colors section view and binds it to {@link #documentColors}.
|
|
199
|
+
*/
|
|
200
|
+
_createDocumentColorsGrid() {
|
|
201
|
+
const bind = Template.bind(this.documentColors, this.documentColors);
|
|
202
|
+
const documentColorsGrid = new ColorGridView(this.locale, {
|
|
203
|
+
columns: this.columns
|
|
204
|
+
});
|
|
205
|
+
documentColorsGrid.delegate('execute').to(this);
|
|
206
|
+
documentColorsGrid.extendTemplate({
|
|
207
|
+
attributes: {
|
|
208
|
+
class: bind.if('isEmpty', 'ck-hidden')
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
documentColorsGrid.items.bindTo(this.documentColors).using(colorObj => {
|
|
212
|
+
const colorTile = new ColorTileView();
|
|
213
|
+
colorTile.set({
|
|
214
|
+
color: colorObj.color,
|
|
215
|
+
hasBorder: colorObj.options && colorObj.options.hasBorder
|
|
216
|
+
});
|
|
217
|
+
if (colorObj.label) {
|
|
218
|
+
colorTile.set({
|
|
219
|
+
label: colorObj.label,
|
|
220
|
+
tooltip: true
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
colorTile.on('execute', () => {
|
|
224
|
+
this.fire('execute', {
|
|
225
|
+
value: colorObj.color
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
return colorTile;
|
|
229
|
+
});
|
|
230
|
+
// Selected color should be cleared when document colors became empty.
|
|
231
|
+
this.documentColors.on('change:isEmpty', (evt, name, val) => {
|
|
232
|
+
if (val) {
|
|
233
|
+
documentColorsGrid.selectedColor = null;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
return documentColorsGrid;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Adds a given color to the document colors list. If possible, the method will attempt to use
|
|
240
|
+
* data from the {@link #colorDefinitions} (label, color options).
|
|
241
|
+
*
|
|
242
|
+
* @param color A string that stores the value of the recently applied color.
|
|
243
|
+
*/
|
|
244
|
+
_addColorToDocumentColors(color) {
|
|
245
|
+
const predefinedColor = this.colorDefinitions
|
|
246
|
+
.find(definition => definition.color === color);
|
|
247
|
+
if (!predefinedColor) {
|
|
248
|
+
this.documentColors.add({
|
|
249
|
+
color,
|
|
250
|
+
label: color,
|
|
251
|
+
options: {
|
|
252
|
+
hasBorder: false
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
this.documentColors.add(Object.assign({}, predefinedColor));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
436
260
|
}
|