@ckeditor/ckeditor5-font 38.2.0-alpha.0 → 38.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/build/font.js +2 -2
  2. package/build/translations/ar.js +1 -1
  3. package/build/translations/az.js +1 -1
  4. package/build/translations/bg.js +1 -1
  5. package/build/translations/bn.js +1 -1
  6. package/build/translations/bs.js +1 -1
  7. package/build/translations/ca.js +1 -1
  8. package/build/translations/cs.js +1 -1
  9. package/build/translations/da.js +1 -1
  10. package/build/translations/de-ch.js +1 -1
  11. package/build/translations/de.js +1 -1
  12. package/build/translations/el.js +1 -1
  13. package/build/translations/en-au.js +1 -1
  14. package/build/translations/en-gb.js +1 -1
  15. package/build/translations/es.js +1 -1
  16. package/build/translations/et.js +1 -1
  17. package/build/translations/fa.js +1 -1
  18. package/build/translations/fi.js +1 -1
  19. package/build/translations/fr.js +1 -1
  20. package/build/translations/gl.js +1 -1
  21. package/build/translations/he.js +1 -1
  22. package/build/translations/hi.js +1 -1
  23. package/build/translations/hr.js +1 -1
  24. package/build/translations/hu.js +1 -1
  25. package/build/translations/id.js +1 -1
  26. package/build/translations/it.js +1 -1
  27. package/build/translations/ja.js +1 -1
  28. package/build/translations/jv.js +1 -1
  29. package/build/translations/ko.js +1 -1
  30. package/build/translations/ku.js +1 -1
  31. package/build/translations/lt.js +1 -1
  32. package/build/translations/lv.js +1 -1
  33. package/build/translations/ms.js +1 -1
  34. package/build/translations/nb.js +1 -1
  35. package/build/translations/ne.js +1 -1
  36. package/build/translations/nl.js +1 -1
  37. package/build/translations/no.js +1 -1
  38. package/build/translations/pl.js +1 -1
  39. package/build/translations/pt-br.js +1 -1
  40. package/build/translations/pt.js +1 -1
  41. package/build/translations/ro.js +1 -1
  42. package/build/translations/ru.js +1 -1
  43. package/build/translations/sk.js +1 -1
  44. package/build/translations/sl.js +1 -1
  45. package/build/translations/sq.js +1 -1
  46. package/build/translations/sr-latn.js +1 -1
  47. package/build/translations/sr.js +1 -1
  48. package/build/translations/sv.js +1 -1
  49. package/build/translations/th.js +1 -1
  50. package/build/translations/tk.js +1 -1
  51. package/build/translations/tr.js +1 -1
  52. package/build/translations/ug.js +1 -1
  53. package/build/translations/uk.js +1 -1
  54. package/build/translations/ur.js +1 -1
  55. package/build/translations/uz.js +1 -1
  56. package/build/translations/vi.js +1 -1
  57. package/build/translations/zh-cn.js +1 -1
  58. package/build/translations/zh.js +1 -1
  59. package/lang/contexts.json +1 -2
  60. package/package.json +2 -3
  61. package/src/augmentation.d.ts +1 -1
  62. package/src/font.d.ts +5 -5
  63. package/src/font.js +5 -5
  64. package/src/fontbackgroundcolor/fontbackgroundcolorcommand.d.ts +2 -2
  65. package/src/fontbackgroundcolor/fontbackgroundcolorcommand.js +2 -2
  66. package/src/fontbackgroundcolor/fontbackgroundcolorediting.d.ts +1 -1
  67. package/src/fontbackgroundcolor/fontbackgroundcolorediting.js +4 -4
  68. package/src/fontbackgroundcolor/fontbackgroundcolorui.d.ts +2 -2
  69. package/src/fontbackgroundcolor/fontbackgroundcolorui.js +2 -2
  70. package/src/fontbackgroundcolor.d.ts +3 -3
  71. package/src/fontbackgroundcolor.js +3 -3
  72. package/src/fontcolor/fontcolorcommand.d.ts +2 -2
  73. package/src/fontcolor/fontcolorcommand.js +2 -2
  74. package/src/fontcolor/fontcolorediting.d.ts +1 -1
  75. package/src/fontcolor/fontcolorediting.js +3 -3
  76. package/src/fontcolor/fontcolorui.d.ts +2 -2
  77. package/src/fontcolor/fontcolorui.js +2 -2
  78. package/src/fontcolor.d.ts +3 -3
  79. package/src/fontcolor.js +3 -3
  80. package/src/fontcommand.d.ts +2 -2
  81. package/src/fontcommand.js +1 -1
  82. package/src/fontconfig.d.ts +2 -2
  83. package/src/fontfamily/fontfamilycommand.d.ts +2 -2
  84. package/src/fontfamily/fontfamilycommand.js +2 -2
  85. package/src/fontfamily/fontfamilyediting.d.ts +1 -1
  86. package/src/fontfamily/fontfamilyediting.js +4 -4
  87. package/src/fontfamily/fontfamilyui.d.ts +1 -1
  88. package/src/fontfamily/fontfamilyui.js +5 -5
  89. package/src/fontfamily/utils.d.ts +1 -1
  90. package/src/fontfamily.d.ts +3 -3
  91. package/src/fontfamily.js +3 -3
  92. package/src/fontsize/fontsizecommand.d.ts +2 -2
  93. package/src/fontsize/fontsizecommand.js +2 -2
  94. package/src/fontsize/fontsizeediting.d.ts +1 -1
  95. package/src/fontsize/fontsizeediting.js +6 -6
  96. package/src/fontsize/fontsizeui.d.ts +1 -1
  97. package/src/fontsize/fontsizeui.js +5 -5
  98. package/src/fontsize/utils.d.ts +1 -1
  99. package/src/fontsize/utils.js +1 -1
  100. package/src/fontsize.d.ts +4 -4
  101. package/src/fontsize.js +4 -4
  102. package/src/index.d.ts +20 -20
  103. package/src/index.js +14 -14
  104. package/src/ui/colorui.d.ts +8 -7
  105. package/src/ui/colorui.js +21 -19
  106. package/src/utils.d.ts +16 -15
  107. package/src/utils.js +13 -14
  108. package/src/documentcolorcollection.d.ts +0 -70
  109. package/src/documentcolorcollection.js +0 -42
  110. package/src/ui/colortableview.d.ts +0 -459
  111. package/src/ui/colortableview.js +0 -645
  112. package/theme/fontcolor.css +0 -75
@@ -5,14 +5,14 @@
5
5
  /**
6
6
  * @module font/ui/colorui
7
7
  */
8
- import { Plugin, type Editor } from 'ckeditor5/src/core';
9
- import { type FONT_BACKGROUND_COLOR, type FONT_COLOR } from '../utils';
10
- import { type default as ColorTableView } from './colortableview';
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core.js';
9
+ import { type ColorSelectorView } from 'ckeditor5/src/ui.js';
10
+ import { type FONT_BACKGROUND_COLOR, type FONT_COLOR } from '../utils.js';
11
11
  /**
12
12
  * The color UI plugin which isolates the common logic responsible for displaying dropdowns with color grids.
13
13
  *
14
14
  * It is used to create the `'fontBackgroundColor'` and `'fontColor'` dropdowns, each hosting
15
- * a {@link module:font/ui/colortableview~ColorTableView}.
15
+ * a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}.
16
16
  */
17
17
  export default class ColorUI extends Plugin {
18
18
  /**
@@ -37,15 +37,16 @@ export default class ColorUI extends Plugin {
37
37
  */
38
38
  columns: number;
39
39
  /**
40
- * Keeps a reference to {@link module:font/ui/colortableview~ColorTableView}.
40
+ * Keeps a reference to {@link module:ui/colorselector/colorselectorview~ColorSelectorView}.
41
41
  */
42
- colorTableView: ColorTableView | undefined;
42
+ colorSelectorView: ColorSelectorView | undefined;
43
43
  /**
44
44
  * Keeps all changes in color picker in one batch while dropdown is open.
45
45
  */
46
46
  private _undoStepBatch;
47
47
  /**
48
- * Creates a plugin which introduces a dropdown with a pre–configured {@link module:font/ui/colortableview~ColorTableView}.
48
+ * Creates a plugin which introduces a dropdown with a pre–configured
49
+ * {@link module:ui/colorselector/colorselectorview~ColorSelectorView}.
49
50
  *
50
51
  * @param config The configuration object.
51
52
  * @param config.commandName The name of the command which will be executed when a color tile is clicked.
package/src/ui/colorui.js CHANGED
@@ -5,18 +5,19 @@
5
5
  /**
6
6
  * @module font/ui/colorui
7
7
  */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { createDropdown, normalizeColorOptions, getLocalizedColorOptions, focusChildOnDropdownOpen } from 'ckeditor5/src/ui';
10
- import { addColorTableToDropdown } from '../utils';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import { createDropdown, normalizeColorOptions, getLocalizedColorOptions, focusChildOnDropdownOpen } from 'ckeditor5/src/ui.js';
10
+ import { addColorSelectorToDropdown } from '../utils.js';
11
11
  /**
12
12
  * The color UI plugin which isolates the common logic responsible for displaying dropdowns with color grids.
13
13
  *
14
14
  * It is used to create the `'fontBackgroundColor'` and `'fontColor'` dropdowns, each hosting
15
- * a {@link module:font/ui/colortableview~ColorTableView}.
15
+ * a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}.
16
16
  */
17
17
  export default class ColorUI extends Plugin {
18
18
  /**
19
- * Creates a plugin which introduces a dropdown with a pre–configured {@link module:font/ui/colortableview~ColorTableView}.
19
+ * Creates a plugin which introduces a dropdown with a pre–configured
20
+ * {@link module:ui/colorselector/colorselectorview~ColorSelectorView}.
20
21
  *
21
22
  * @param config The configuration object.
22
23
  * @param config.commandName The name of the command which will be executed when a color tile is clicked.
@@ -32,7 +33,7 @@ export default class ColorUI extends Plugin {
32
33
  this.icon = icon;
33
34
  this.dropdownLabel = dropdownLabel;
34
35
  this.columns = editor.config.get(`${this.componentName}.columns`);
35
- this.colorTableView = undefined;
36
+ this.colorSelectorView = undefined;
36
37
  }
37
38
  /**
38
39
  * @inheritDoc
@@ -52,7 +53,7 @@ export default class ColorUI extends Plugin {
52
53
  const dropdownView = createDropdown(locale);
53
54
  // Font color dropdown rendering is deferred once it gets open to improve performance (#6192).
54
55
  let dropdownContentRendered = false;
55
- this.colorTableView = addColorTableToDropdown({
56
+ this.colorSelectorView = addColorSelectorToDropdown({
56
57
  dropdownView,
57
58
  colors: localizedColors.map(option => ({
58
59
  label: option.label,
@@ -66,9 +67,9 @@ export default class ColorUI extends Plugin {
66
67
  colorPickerLabel: t('Color picker'),
67
68
  documentColorsLabel: documentColorsCount !== 0 ? t('Document colors') : '',
68
69
  documentColorsCount: documentColorsCount === undefined ? this.columns : documentColorsCount,
69
- colorPickerConfig: hasColorPicker ? (componentConfig.colorPicker || {}) : false
70
+ colorPickerViewConfig: hasColorPicker ? (componentConfig.colorPicker || {}) : false
70
71
  });
71
- this.colorTableView.bind('selectedColor').to(command, 'value');
72
+ this.colorSelectorView.bind('selectedColor').to(command, 'value');
72
73
  dropdownView.buttonView.set({
73
74
  label: this.dropdownLabel,
74
75
  icon: this.icon,
@@ -80,7 +81,7 @@ export default class ColorUI extends Plugin {
80
81
  }
81
82
  });
82
83
  dropdownView.bind('isEnabled').to(command);
83
- this.colorTableView.on('execute', (evt, data) => {
84
+ this.colorSelectorView.on('execute', (evt, data) => {
84
85
  if (dropdownView.isOpen) {
85
86
  editor.execute(this.commandName, {
86
87
  value: data.value,
@@ -90,11 +91,14 @@ export default class ColorUI extends Plugin {
90
91
  if (data.source !== 'colorPicker') {
91
92
  editor.editing.view.focus();
92
93
  }
94
+ if (data.source === 'colorPickerSaveButton') {
95
+ dropdownView.isOpen = false;
96
+ }
93
97
  });
94
- this.colorTableView.on('showColorPicker', () => {
98
+ this.colorSelectorView.on('colorPicker:show', () => {
95
99
  this._undoStepBatch = editor.model.createBatch();
96
100
  });
97
- this.colorTableView.on('cancel', () => {
101
+ this.colorSelectorView.on('colorPicker:cancel', () => {
98
102
  if (this._undoStepBatch.operations.length) {
99
103
  // We need to close the dropdown before the undo batch.
100
104
  // Otherwise, ColorUI treats undo as a selected color change,
@@ -108,20 +112,18 @@ export default class ColorUI extends Plugin {
108
112
  dropdownView.on('change:isOpen', (evt, name, isVisible) => {
109
113
  if (!dropdownContentRendered) {
110
114
  dropdownContentRendered = true;
111
- dropdownView.colorTableView.appendUI();
115
+ dropdownView.colorSelectorView.appendUI();
112
116
  }
113
117
  if (isVisible) {
114
118
  if (documentColorsCount !== 0) {
115
- this.colorTableView.updateDocumentColors(editor.model, this.componentName);
119
+ this.colorSelectorView.updateDocumentColors(editor.model, this.componentName);
116
120
  }
117
- this.colorTableView.updateSelectedColors();
118
- }
119
- else {
120
- this.colorTableView.showColorGrids();
121
+ this.colorSelectorView.updateSelectedColors();
122
+ this.colorSelectorView.showColorGridsFragment();
121
123
  }
122
124
  });
123
125
  // Accessibility: focus the first active color when opening the dropdown.
124
- focusChildOnDropdownOpen(dropdownView, () => dropdownView.colorTableView.colorGridsPageView.staticColorsGrid.items.find((item) => item.isOn));
126
+ focusChildOnDropdownOpen(dropdownView, () => dropdownView.colorSelectorView.colorGridsFragmentView.staticColorsGrid.items.find((item) => item.isOn));
125
127
  return dropdownView;
126
128
  });
127
129
  }
package/src/utils.d.ts CHANGED
@@ -5,11 +5,10 @@
5
5
  /**
6
6
  * @module font/utils
7
7
  */
8
- import ColorTableView from './ui/colortableview';
9
- import type { FontFamilyOption, FontSizeOption } from './fontconfig';
10
- import type { ColorDefinition, ColorPickerConfig, DropdownView } from 'ckeditor5/src/ui';
11
- import type { ArrayOrItem } from 'ckeditor5/src/utils';
12
- import type { ViewAttributeElement, ViewElement, MatcherPattern, ViewElementDefinition, DowncastConversionApi } from 'ckeditor5/src/engine';
8
+ import type { FontFamilyOption, FontSizeOption } from './fontconfig.js';
9
+ import { ColorSelectorView, type ColorDefinition, type ColorPickerViewConfig, type DropdownView } from 'ckeditor5/src/ui.js';
10
+ import type { ArrayOrItem } from 'ckeditor5/src/utils.js';
11
+ import type { ViewAttributeElement, ViewElement, MatcherPattern, ViewElementDefinition, DowncastConversionApi } from 'ckeditor5/src/engine.js';
13
12
  /**
14
13
  * The name of the font size plugin.
15
14
  */
@@ -55,25 +54,27 @@ export declare function renderUpcastAttribute(styleAttr: string): (viewElement:
55
54
  */
56
55
  export declare function renderDowncastElement(styleAttr: string): (modelAttributeValue: string, { writer }: DowncastConversionApi) => ViewAttributeElement;
57
56
  /**
58
- * A helper that adds {@link module:font/ui/colortableview~ColorTableView} to the color dropdown with proper initial values.
57
+ * A helper that adds {@link module:ui/colorselector/colorselectorview~ColorSelectorView} to the color dropdown with proper initial values.
59
58
  *
60
- * @param config.dropdownView The dropdown view to which a {@link module:font/ui/colortableview~ColorTableView} will be added.
61
- * @param config.colors An array with definitions representing colors to be displayed in the color table.
59
+ * @param config.dropdownView The dropdown view to which a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}
60
+ * will be added.
61
+ * @param config.colors An array with definitions representing colors to be displayed in the color selector.
62
62
  * @param config.removeButtonLabel The label for the button responsible for removing the color.
63
63
  * @param config.documentColorsLabel The label for the section with document colors.
64
64
  * @param config.documentColorsCount The number of document colors inside the dropdown.
65
- * @returns The new color table view.
65
+ * @param config.colorPickerViewConfig Configuration of the color picker view.
66
+ * @returns The new color selector view.
66
67
  */
67
- export declare function addColorTableToDropdown({ dropdownView, colors, columns, removeButtonLabel, colorPickerLabel, documentColorsLabel, documentColorsCount, colorPickerConfig }: {
68
- dropdownView: ColorTableDropdownView;
68
+ export declare function addColorSelectorToDropdown({ dropdownView, colors, columns, removeButtonLabel, colorPickerLabel, documentColorsLabel, documentColorsCount, colorPickerViewConfig }: {
69
+ dropdownView: ColorSelectorDropdownView;
69
70
  colors: Array<ColorDefinition>;
70
71
  columns: number;
71
72
  removeButtonLabel: string;
72
73
  colorPickerLabel: string;
73
74
  documentColorsLabel?: string;
74
75
  documentColorsCount?: number;
75
- colorPickerConfig: ColorPickerConfig | false;
76
- }): ColorTableView;
77
- export type ColorTableDropdownView = DropdownView & {
78
- colorTableView?: ColorTableView;
76
+ colorPickerViewConfig: ColorPickerViewConfig | false;
77
+ }): ColorSelectorView;
78
+ export type ColorSelectorDropdownView = DropdownView & {
79
+ colorSelectorView?: ColorSelectorView;
79
80
  };
package/src/utils.js CHANGED
@@ -2,10 +2,7 @@
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
- * @module font/utils
7
- */
8
- import ColorTableView from './ui/colortableview';
5
+ import { ColorSelectorView } from 'ckeditor5/src/ui.js';
9
6
  /**
10
7
  * The name of the font size plugin.
11
8
  */
@@ -66,29 +63,31 @@ export function renderDowncastElement(styleAttr) {
66
63
  }, { priority: 7 });
67
64
  }
68
65
  /**
69
- * A helper that adds {@link module:font/ui/colortableview~ColorTableView} to the color dropdown with proper initial values.
66
+ * A helper that adds {@link module:ui/colorselector/colorselectorview~ColorSelectorView} to the color dropdown with proper initial values.
70
67
  *
71
- * @param config.dropdownView The dropdown view to which a {@link module:font/ui/colortableview~ColorTableView} will be added.
72
- * @param config.colors An array with definitions representing colors to be displayed in the color table.
68
+ * @param config.dropdownView The dropdown view to which a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}
69
+ * will be added.
70
+ * @param config.colors An array with definitions representing colors to be displayed in the color selector.
73
71
  * @param config.removeButtonLabel The label for the button responsible for removing the color.
74
72
  * @param config.documentColorsLabel The label for the section with document colors.
75
73
  * @param config.documentColorsCount The number of document colors inside the dropdown.
76
- * @returns The new color table view.
74
+ * @param config.colorPickerViewConfig Configuration of the color picker view.
75
+ * @returns The new color selector view.
77
76
  */
78
- export function addColorTableToDropdown({ dropdownView, colors, columns, removeButtonLabel, colorPickerLabel, documentColorsLabel, documentColorsCount, colorPickerConfig }) {
77
+ export function addColorSelectorToDropdown({ dropdownView, colors, columns, removeButtonLabel, colorPickerLabel, documentColorsLabel, documentColorsCount, colorPickerViewConfig }) {
79
78
  const locale = dropdownView.locale;
80
- const colorTableView = new ColorTableView(locale, {
79
+ const colorSelectorView = new ColorSelectorView(locale, {
81
80
  colors,
82
81
  columns,
83
82
  removeButtonLabel,
84
83
  colorPickerLabel,
85
84
  documentColorsLabel,
86
85
  documentColorsCount,
87
- colorPickerConfig
86
+ colorPickerViewConfig
88
87
  });
89
- dropdownView.colorTableView = colorTableView;
90
- dropdownView.panelView.children.add(colorTableView);
91
- return colorTableView;
88
+ dropdownView.colorSelectorView = colorSelectorView;
89
+ dropdownView.panelView.children.add(colorSelectorView);
90
+ return colorSelectorView;
92
91
  }
93
92
  /**
94
93
  * Fixes the color value string.
@@ -1,70 +0,0 @@
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 font/documentcolorcollection
7
- */
8
- import type { ColorDefinition } from 'ckeditor5/src/ui';
9
- import { Collection, type CollectionAddEvent, type CollectionRemoveEvent, type CollectionChangeEvent } from 'ckeditor5/src/utils';
10
- declare const DocumentColorCollection_base: import("ckeditor5/src/utils").Mixed<{
11
- new (options?: {
12
- readonly idProperty?: string | undefined;
13
- } | undefined): Collection<ColorDefinition>;
14
- new (initialItems: Iterable<ColorDefinition>, options?: {
15
- readonly idProperty?: string | undefined;
16
- } | undefined): Collection<ColorDefinition>;
17
- }, import("ckeditor5/src/utils").Observable>;
18
- /**
19
- * A collection to store document colors. It enforces colors to be unique.
20
- */
21
- export default class DocumentColorCollection extends DocumentColorCollection_base {
22
- /**
23
- * Indicates whether the document color collection is empty.
24
- *
25
- * @observable
26
- */
27
- readonly isEmpty: boolean;
28
- constructor(options?: any);
29
- /**
30
- * Adds a color to the document color collection.
31
- *
32
- * This method ensures that no color duplicates are inserted (compared using
33
- * the color value of the {@link module:ui/colorgrid/colorgridview~ColorDefinition}).
34
- *
35
- * If the item does not have an ID, it will be automatically generated and set on the item.
36
- *
37
- * @param index The position of the item in the collection. The item is pushed to the collection when `index` is not specified.
38
- * @fires add
39
- * @fires change
40
- */
41
- add(item: ColorDefinition, index?: number): this;
42
- /**
43
- * Checks if an object with given colors is present in the document color collection.
44
- */
45
- hasColor(color: string): boolean;
46
- }
47
- /**
48
- * Fired when the collection was changed due to adding or removing items.
49
- *
50
- * @eventName ~DocumentColorCollection#change
51
- * @param data Changed items.
52
- */
53
- export type DocumentColorCollectionChangeEvent = CollectionChangeEvent;
54
- /**
55
- * Fired when an item is added to the collection.
56
- *
57
- * @eventName ~DocumentColorCollection#add
58
- * @param item The added item.
59
- * @param index An index where the addition occurred.
60
- */
61
- export type DocumentColorCollectionAddEvent = CollectionAddEvent;
62
- /**
63
- * Fired when an item is removed from the collection.
64
- *
65
- * @eventName ~DocumentColorCollection#remove
66
- * @param item The removed item.
67
- * @param index Index from which item was removed.
68
- */
69
- export type DocumentColorCollectionRemoveEvent = CollectionRemoveEvent;
70
- export {};
@@ -1,42 +0,0 @@
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
- import { Collection, ObservableMixin } from 'ckeditor5/src/utils';
6
- /**
7
- * A collection to store document colors. It enforces colors to be unique.
8
- */
9
- export default class DocumentColorCollection extends ObservableMixin((Collection)) {
10
- constructor(options) {
11
- super(options);
12
- this.set('isEmpty', true);
13
- this.on('change', () => {
14
- this.set('isEmpty', this.length === 0);
15
- });
16
- }
17
- /**
18
- * Adds a color to the document color collection.
19
- *
20
- * This method ensures that no color duplicates are inserted (compared using
21
- * the color value of the {@link module:ui/colorgrid/colorgridview~ColorDefinition}).
22
- *
23
- * If the item does not have an ID, it will be automatically generated and set on the item.
24
- *
25
- * @param index The position of the item in the collection. The item is pushed to the collection when `index` is not specified.
26
- * @fires add
27
- * @fires change
28
- */
29
- add(item, index) {
30
- if (this.find(element => element.color === item.color)) {
31
- // No duplicates are allowed.
32
- return this;
33
- }
34
- return super.add(item, index);
35
- }
36
- /**
37
- * Checks if an object with given colors is present in the document color collection.
38
- */
39
- hasColor(color) {
40
- return !!this.find(item => item.color === color);
41
- }
42
- }