@ckeditor/ckeditor5-font 36.0.1 → 37.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/build/font.js +1 -1
  2. package/package.json +20 -15
  3. package/src/documentcolorcollection.d.ts +47 -0
  4. package/src/documentcolorcollection.js +34 -63
  5. package/src/font.d.ts +34 -0
  6. package/src/font.js +12 -19
  7. package/src/fontbackgroundcolor/fontbackgroundcolorcommand.d.ts +32 -0
  8. package/src/fontbackgroundcolor/fontbackgroundcolorcommand.js +9 -15
  9. package/src/fontbackgroundcolor/fontbackgroundcolorediting.d.ts +31 -0
  10. package/src/fontbackgroundcolor/fontbackgroundcolorediting.js +102 -115
  11. package/src/fontbackgroundcolor/fontbackgroundcolorui.d.ts +27 -0
  12. package/src/fontbackgroundcolor/fontbackgroundcolorui.js +18 -25
  13. package/src/fontbackgroundcolor.d.ts +33 -0
  14. package/src/fontbackgroundcolor.js +12 -165
  15. package/src/fontcolor/fontcolorcommand.d.ts +31 -0
  16. package/src/fontcolor/fontcolorcommand.js +9 -15
  17. package/src/fontcolor/fontcolorediting.d.ts +31 -0
  18. package/src/fontcolor/fontcolorediting.js +115 -128
  19. package/src/fontcolor/fontcolorui.d.ts +27 -0
  20. package/src/fontcolor/fontcolorui.js +18 -25
  21. package/src/fontcolor.d.ts +29 -0
  22. package/src/fontcolor.js +12 -168
  23. package/src/fontcommand.d.ts +46 -0
  24. package/src/fontcommand.js +54 -78
  25. package/src/fontconfig.d.ts +399 -0
  26. package/src/fontconfig.js +5 -0
  27. package/src/fontfamily/fontfamilycommand.d.ts +31 -0
  28. package/src/fontfamily/fontfamilycommand.js +9 -15
  29. package/src/fontfamily/fontfamilyediting.d.ts +45 -0
  30. package/src/fontfamily/fontfamilyediting.js +96 -116
  31. package/src/fontfamily/fontfamilyui.d.ts +35 -0
  32. package/src/fontfamily/fontfamilyui.js +90 -122
  33. package/src/fontfamily/utils.d.ts +15 -0
  34. package/src/fontfamily/utils.js +66 -79
  35. package/src/fontfamily.d.ts +29 -0
  36. package/src/fontfamily.js +12 -112
  37. package/src/fontsize/fontsizecommand.d.ts +31 -0
  38. package/src/fontsize/fontsizecommand.js +9 -15
  39. package/src/fontsize/fontsizeediting.d.ts +50 -0
  40. package/src/fontsize/fontsizeediting.js +138 -169
  41. package/src/fontsize/fontsizeui.d.ts +36 -0
  42. package/src/fontsize/fontsizeui.js +98 -130
  43. package/src/fontsize/utils.d.ts +12 -0
  44. package/src/fontsize/utils.js +145 -174
  45. package/src/fontsize.d.ts +40 -0
  46. package/src/fontsize.js +21 -141
  47. package/src/index.d.ts +20 -0
  48. package/src/index.js +0 -2
  49. package/src/ui/colortableview.d.ts +167 -0
  50. package/src/ui/colortableview.js +240 -416
  51. package/src/ui/colorui.d.ts +64 -0
  52. package/src/ui/colorui.js +79 -132
  53. package/src/utils.d.ts +77 -0
  54. package/src/utils.js +42 -72
@@ -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
- * Creates a view to be inserted as a child of {@link module:ui/dropdown/dropdownview~DropdownView}.
39
- *
40
- * @param {module:utils/locale~Locale} [locale] The localization services instance.
41
- * @param {Object} config The configuration object.
42
- * @param {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>} config.colors An array with definitions of colors to
43
- * be displayed in the table.
44
- * @param {Number} config.columns The number of columns in the color grid.
45
- * @param {String} config.removeButtonLabel The label of the button responsible for removing the color.
46
- * @param {String} config.documentColorsLabel The label for the section with the document colors.
47
- * @param {Number} config.documentColorsCount The number of colors in the document colors section inside the color dropdown.
48
- */
49
- constructor( locale, { colors, columns, removeButtonLabel, documentColorsLabel, documentColorsCount } ) {
50
- super( locale );
51
-
52
- /**
53
- * A collection of the children of the table.
54
- *
55
- * @readonly
56
- * @member {module:ui/viewcollection~ViewCollection}
57
- */
58
- this.items = this.createCollection();
59
-
60
- /**
61
- * An array with objects representing colors to be displayed in the grid.
62
- *
63
- * @type {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>}
64
- */
65
- this.colorDefinitions = colors;
66
-
67
- /**
68
- * Tracks information about the DOM focus in the list.
69
- *
70
- * @readonly
71
- * @member {module:utils/focustracker~FocusTracker}
72
- */
73
- this.focusTracker = new FocusTracker();
74
-
75
- /**
76
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
77
- *
78
- * @readonly
79
- * @member {module:utils/keystrokehandler~KeystrokeHandler}
80
- */
81
- this.keystrokes = new KeystrokeHandler();
82
-
83
- /**
84
- * Keeps the value of the command associated with the table for the current selection.
85
- *
86
- * @type {String}
87
- */
88
- this.set( 'selectedColor' );
89
-
90
- /**
91
- * The label of the button responsible for removing color attributes.
92
- *
93
- * @type {String}
94
- */
95
- this.removeButtonLabel = removeButtonLabel;
96
-
97
- /**
98
- * The number of columns in the color grid.
99
- *
100
- * @type {Number}
101
- */
102
- this.columns = columns;
103
-
104
- /**
105
- * A collection of definitions that store the document colors.
106
- *
107
- * @readonly
108
- * @member {module:font/documentcolorcollection~DocumentColorCollection}
109
- */
110
- this.documentColors = new DocumentColorCollection();
111
-
112
- /**
113
- * The maximum number of colors in the document colors section.
114
- * If it equals 0, the document colors section is not added.
115
- *
116
- * @readonly
117
- * @type {Number}
118
- */
119
- this.documentColorsCount = documentColorsCount;
120
-
121
- /**
122
- * A collection of views that can be focused in the view.
123
- *
124
- * @readonly
125
- * @protected
126
- * @member {module:ui/viewcollection~ViewCollection}
127
- */
128
- this._focusables = new ViewCollection();
129
-
130
- /**
131
- * Preserves the reference to {@link module:ui/colorgrid/colorgrid~ColorGridView} used to create
132
- * the default (static) color set.
133
- *
134
- * The property is loaded once the the parent dropdown is opened the first time.
135
- *
136
- * @readonly
137
- * @member {module:ui/colorgrid/colorgrid~ColorGridView|undefined} #staticColorsGrid
138
- */
139
-
140
- /**
141
- * Preserves the reference to {@link module:ui/colorgrid/colorgrid~ColorGridView} used to create
142
- * the document colors. It remains undefined if the document colors feature is disabled.
143
- *
144
- * The property is loaded once the the parent dropdown is opened the first time.
145
- *
146
- * @readonly
147
- * @member {module:ui/colorgrid/colorgrid~ColorGridView|undefined} #documentColorsGrid
148
- */
149
-
150
- /**
151
- * Helps cycling over focusable {@link #items} in the list.
152
- *
153
- * @readonly
154
- * @protected
155
- * @member {module:ui/focuscycler~FocusCycler}
156
- */
157
- this._focusCycler = new FocusCycler( {
158
- focusables: this._focusables,
159
- focusTracker: this.focusTracker,
160
- keystrokeHandler: this.keystrokes,
161
- actions: {
162
- // Navigate list items backwards using the <kbd>Shift</kbd> + <kbd>Tab</kbd> keystroke.
163
- focusPrevious: 'shift + tab',
164
-
165
- // Navigate list items forwards using the <kbd>Tab</kbd> key.
166
- focusNext: 'tab'
167
- }
168
- } );
169
-
170
- /**
171
- * Document color section's label.
172
- *
173
- * @private
174
- * @readonly
175
- * @type {String}
176
- */
177
- this._documentColorsLabel = documentColorsLabel;
178
-
179
- this.setTemplate( {
180
- tag: 'div',
181
- attributes: {
182
- class: [
183
- 'ck',
184
- 'ck-color-table'
185
- ]
186
- },
187
- children: this.items
188
- } );
189
-
190
- this.items.add( this._createRemoveColorButton() );
191
- }
192
-
193
- /**
194
- * Scans through the editor model and searches for text node attributes with the given attribute name.
195
- * Found entries are set as document colors.
196
- *
197
- * All the previously stored document colors will be lost in the process.
198
- *
199
- * @param {module:engine/model/model~Model} model The model used as a source to obtain the document colors.
200
- * @param {String} attributeName Determines the name of the related model's attribute for a given dropdown.
201
- */
202
- updateDocumentColors( model, attributeName ) {
203
- const document = model.document;
204
- const maxCount = this.documentColorsCount;
205
-
206
- this.documentColors.clear();
207
-
208
- for ( const rootName of document.getRootNames() ) {
209
- const root = document.getRoot( rootName );
210
- const range = model.createRangeIn( root );
211
-
212
- for ( const node of range.getItems() ) {
213
- if ( node.is( '$textProxy' ) && node.hasAttribute( attributeName ) ) {
214
- this._addColorToDocumentColors( node.getAttribute( attributeName ) );
215
-
216
- if ( this.documentColors.length >= maxCount ) {
217
- return;
218
- }
219
- }
220
- }
221
- }
222
- }
223
-
224
- /**
225
- * Refreshes the state of the selected color in one or both {@link module:ui/colorgrid/colorgrid~ColorGridView}s
226
- * available in the {@link module:font/ui/colortableview~ColorTableView}. It guarantees that the selection will occur only in one
227
- * of them.
228
- */
229
- updateSelectedColors() {
230
- const documentColorsGrid = this.documentColorsGrid;
231
- const staticColorsGrid = this.staticColorsGrid;
232
- const selectedColor = this.selectedColor;
233
-
234
- staticColorsGrid.selectedColor = selectedColor;
235
-
236
- if ( documentColorsGrid ) {
237
- documentColorsGrid.selectedColor = selectedColor;
238
- }
239
- }
240
-
241
- /**
242
- * @inheritDoc
243
- */
244
- render() {
245
- super.render();
246
-
247
- // Start listening for the keystrokes coming from #element.
248
- this.keystrokes.listenTo( this.element );
249
- }
250
-
251
- /**
252
- * @inheritDoc
253
- */
254
- destroy() {
255
- super.destroy();
256
-
257
- this.focusTracker.destroy();
258
- this.keystrokes.destroy();
259
- }
260
-
261
- /**
262
- * Appends {@link #staticColorsGrid} and {@link #documentColorsGrid} views.
263
- */
264
- appendGrids() {
265
- if ( this.staticColorsGrid ) {
266
- return;
267
- }
268
-
269
- this.staticColorsGrid = this._createStaticColorsGrid();
270
-
271
- this.items.add( this.staticColorsGrid );
272
- this.focusTracker.add( this.staticColorsGrid.element );
273
- this._focusables.add( this.staticColorsGrid );
274
-
275
- if ( this.documentColorsCount ) {
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
  }