@ckeditor/ckeditor5-ui 38.0.1 → 38.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/lang/translations/it.po +1 -1
  2. package/package.json +3 -32
  3. package/src/augmentation.d.ts +86 -86
  4. package/src/augmentation.js +5 -5
  5. package/src/bindings/addkeyboardhandlingforgrid.d.ts +27 -27
  6. package/src/bindings/addkeyboardhandlingforgrid.js +107 -107
  7. package/src/bindings/clickoutsidehandler.d.ts +28 -28
  8. package/src/bindings/clickoutsidehandler.js +36 -36
  9. package/src/bindings/csstransitiondisablermixin.d.ts +40 -40
  10. package/src/bindings/csstransitiondisablermixin.js +55 -55
  11. package/src/bindings/injectcsstransitiondisabler.d.ts +59 -59
  12. package/src/bindings/injectcsstransitiondisabler.js +71 -71
  13. package/src/bindings/preventdefault.d.ts +33 -33
  14. package/src/bindings/preventdefault.js +34 -34
  15. package/src/bindings/submithandler.d.ts +57 -57
  16. package/src/bindings/submithandler.js +47 -47
  17. package/src/button/button.d.ts +178 -178
  18. package/src/button/button.js +5 -5
  19. package/src/button/buttonview.d.ts +177 -177
  20. package/src/button/buttonview.js +231 -231
  21. package/src/button/switchbuttonview.d.ts +45 -45
  22. package/src/button/switchbuttonview.js +75 -75
  23. package/src/colorgrid/colorgridview.d.ts +132 -132
  24. package/src/colorgrid/colorgridview.js +124 -124
  25. package/src/colorgrid/colortileview.d.ts +28 -28
  26. package/src/colorgrid/colortileview.js +40 -40
  27. package/src/colorgrid/utils.d.ts +47 -47
  28. package/src/colorgrid/utils.js +84 -84
  29. package/src/colorpicker/colorpickerview.d.ts +110 -110
  30. package/src/colorpicker/colorpickerview.js +253 -250
  31. package/src/colorpicker/utils.d.ts +35 -35
  32. package/src/colorpicker/utils.js +99 -99
  33. package/src/componentfactory.d.ts +81 -81
  34. package/src/componentfactory.js +104 -104
  35. package/src/dropdown/button/dropdownbutton.d.ts +25 -25
  36. package/src/dropdown/button/dropdownbutton.js +5 -5
  37. package/src/dropdown/button/dropdownbuttonview.d.ts +48 -48
  38. package/src/dropdown/button/dropdownbuttonview.js +66 -66
  39. package/src/dropdown/button/splitbuttonview.d.ts +161 -161
  40. package/src/dropdown/button/splitbuttonview.js +152 -152
  41. package/src/dropdown/dropdownpanelfocusable.d.ts +21 -21
  42. package/src/dropdown/dropdownpanelfocusable.js +5 -5
  43. package/src/dropdown/dropdownpanelview.d.ts +62 -62
  44. package/src/dropdown/dropdownpanelview.js +96 -96
  45. package/src/dropdown/dropdownview.d.ts +315 -315
  46. package/src/dropdown/dropdownview.js +378 -378
  47. package/src/dropdown/utils.d.ts +221 -221
  48. package/src/dropdown/utils.js +434 -434
  49. package/src/editableui/editableuiview.d.ts +72 -72
  50. package/src/editableui/editableuiview.js +112 -112
  51. package/src/editableui/inline/inlineeditableuiview.d.ts +40 -40
  52. package/src/editableui/inline/inlineeditableuiview.js +48 -48
  53. package/src/editorui/bodycollection.d.ts +55 -51
  54. package/src/editorui/bodycollection.js +84 -78
  55. package/src/editorui/boxed/boxededitoruiview.d.ts +40 -40
  56. package/src/editorui/boxed/boxededitoruiview.js +81 -81
  57. package/src/editorui/editorui.d.ts +282 -274
  58. package/src/editorui/editorui.js +410 -388
  59. package/src/editorui/editoruiview.d.ts +39 -39
  60. package/src/editorui/editoruiview.js +38 -38
  61. package/src/editorui/poweredby.d.ts +71 -76
  62. package/src/editorui/poweredby.js +294 -291
  63. package/src/focuscycler.d.ts +183 -183
  64. package/src/focuscycler.js +220 -220
  65. package/src/formheader/formheaderview.d.ts +53 -53
  66. package/src/formheader/formheaderview.js +63 -63
  67. package/src/icon/iconview.d.ts +78 -78
  68. package/src/icon/iconview.js +112 -112
  69. package/src/iframe/iframeview.d.ts +50 -50
  70. package/src/iframe/iframeview.js +63 -63
  71. package/src/index.d.ts +62 -61
  72. package/src/index.js +61 -60
  73. package/src/input/inputview.d.ts +121 -121
  74. package/src/input/inputview.js +106 -106
  75. package/src/inputnumber/inputnumberview.d.ts +49 -49
  76. package/src/inputnumber/inputnumberview.js +40 -40
  77. package/src/inputtext/inputtextview.d.ts +18 -18
  78. package/src/inputtext/inputtextview.js +27 -27
  79. package/src/label/labelview.d.ts +36 -36
  80. package/src/label/labelview.js +41 -41
  81. package/src/labeledfield/labeledfieldview.d.ts +182 -182
  82. package/src/labeledfield/labeledfieldview.js +157 -157
  83. package/src/labeledfield/utils.d.ts +93 -93
  84. package/src/labeledfield/utils.js +131 -131
  85. package/src/labeledinput/labeledinputview.d.ts +125 -125
  86. package/src/labeledinput/labeledinputview.js +125 -125
  87. package/src/list/listitemview.d.ts +35 -35
  88. package/src/list/listitemview.js +40 -40
  89. package/src/list/listseparatorview.d.ts +18 -18
  90. package/src/list/listseparatorview.js +28 -28
  91. package/src/list/listview.d.ts +65 -65
  92. package/src/list/listview.js +90 -90
  93. package/src/model.d.ts +22 -22
  94. package/src/model.js +31 -31
  95. package/src/notification/notification.d.ts +211 -211
  96. package/src/notification/notification.js +187 -187
  97. package/src/panel/balloon/balloonpanelview.d.ts +685 -685
  98. package/src/panel/balloon/balloonpanelview.js +988 -988
  99. package/src/panel/balloon/contextualballoon.d.ts +299 -299
  100. package/src/panel/balloon/contextualballoon.js +572 -572
  101. package/src/panel/sticky/stickypanelview.d.ts +132 -132
  102. package/src/panel/sticky/stickypanelview.js +139 -139
  103. package/src/template.d.ts +942 -942
  104. package/src/template.js +1294 -1294
  105. package/src/toolbar/balloon/balloontoolbar.d.ts +122 -122
  106. package/src/toolbar/balloon/balloontoolbar.js +300 -300
  107. package/src/toolbar/block/blockbuttonview.d.ts +35 -35
  108. package/src/toolbar/block/blockbuttonview.js +41 -41
  109. package/src/toolbar/block/blocktoolbar.d.ts +161 -153
  110. package/src/toolbar/block/blocktoolbar.js +391 -374
  111. package/src/toolbar/normalizetoolbarconfig.d.ts +39 -39
  112. package/src/toolbar/normalizetoolbarconfig.js +51 -51
  113. package/src/toolbar/toolbarlinebreakview.d.ts +18 -18
  114. package/src/toolbar/toolbarlinebreakview.js +28 -28
  115. package/src/toolbar/toolbarseparatorview.d.ts +18 -18
  116. package/src/toolbar/toolbarseparatorview.js +28 -28
  117. package/src/toolbar/toolbarview.d.ts +265 -265
  118. package/src/toolbar/toolbarview.js +717 -717
  119. package/src/tooltipmanager.d.ts +180 -180
  120. package/src/tooltipmanager.js +353 -353
  121. package/src/view.d.ts +422 -422
  122. package/src/view.js +396 -396
  123. package/src/viewcollection.d.ts +139 -139
  124. package/src/viewcollection.js +206 -206
  125. package/theme/components/colorpicker/colorpicker.css +4 -4
  126. package/theme/globals/_poweredby.css +5 -1
  127. package/theme/icons/project-logo.svg +1 -1
@@ -1,250 +1,253 @@
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 ui/colorpicker/colorpickerview
7
- */
8
- import { convertColor, convertToHex } from './utils';
9
- import { global, env } from '@ckeditor/ckeditor5-utils';
10
- import { debounce } from 'lodash-es';
11
- import View from '../view';
12
- import LabeledFieldView from '../labeledfield/labeledfieldview';
13
- import { createLabeledInputText } from '../labeledfield/utils';
14
- import 'vanilla-colorful/hex-color-picker.js';
15
- import '../../theme/components/colorpicker/colorpicker.css';
16
- const waitingTime = 150;
17
- export default class ColorPickerView extends View {
18
- /**
19
- * Creates a view of color picker.
20
- *
21
- * @param locale
22
- * @param config
23
- */
24
- constructor(locale, config) {
25
- super(locale);
26
- this.set('color', '');
27
- this.set('_hexColor', '');
28
- this._format = config.format || 'hsl';
29
- this.hexInputRow = this._createInputRow();
30
- const children = this.createCollection();
31
- children.add(this.hexInputRow);
32
- this.setTemplate({
33
- tag: 'div',
34
- attributes: {
35
- class: ['ck', 'ck-color-picker'],
36
- tabindex: -1
37
- },
38
- children
39
- });
40
- this._debounceColorPickerEvent = debounce((color) => {
41
- this.set('color', color);
42
- }, waitingTime, {
43
- leading: true
44
- });
45
- // Sets color in the picker if color was updated.
46
- this.on('set:color', (evt, propertyName, newValue) => {
47
- // The color needs always to be kept in the output format.
48
- evt.return = convertColor(newValue, this._format);
49
- });
50
- this.on('change:color', () => {
51
- this._hexColor = convertColorToCommonHexFormat(this.color);
52
- });
53
- this.on('change:_hexColor', () => {
54
- this.picker.setAttribute('color', this._hexColor);
55
- // There has to be two way binding between properties.
56
- // Extra precaution has to be taken to trigger change back only when the color really changes.
57
- if (convertColorToCommonHexFormat(this.color) != convertColorToCommonHexFormat(this._hexColor)) {
58
- this.color = this._hexColor;
59
- }
60
- });
61
- }
62
- /**
63
- * Renders color picker in the view.
64
- */
65
- render() {
66
- super.render();
67
- this.picker = global.document.createElement('hex-color-picker');
68
- this.picker.setAttribute('class', 'hex-color-picker');
69
- this.picker.setAttribute('tabindex', '-1');
70
- this._createSlidersView();
71
- if (this.element) {
72
- this.element.insertBefore(this.picker, this.hexInputRow.element);
73
- // Create custom stylesheet with a look of focused pointer in color picker and append it into the color picker shadowDom
74
- const styleSheetForFocusedColorPicker = document.createElement('style');
75
- styleSheetForFocusedColorPicker.textContent = '[role="slider"]:focus [part$="pointer"] {' +
76
- 'border: 1px solid #fff;' +
77
- 'outline: 1px solid var(--ck-color-focus-border);' +
78
- 'box-shadow: 0 0 0 2px #fff;' +
79
- '}';
80
- this.picker.shadowRoot.appendChild(styleSheetForFocusedColorPicker);
81
- }
82
- this.picker.addEventListener('color-changed', event => {
83
- const customEvent = event;
84
- const color = customEvent.detail.value;
85
- this._debounceColorPickerEvent(color);
86
- });
87
- }
88
- /**
89
- * Focuses the first pointer in color picker.
90
- *
91
- */
92
- focus() {
93
- // In some browsers we need to move the focus to the input first.
94
- // Otherwise, the color picker doesn't behave as expected.
95
- // In FF, after selecting the color via slider, it instantly moves back to the previous color.
96
- // In all iOS browsers and desktop Safari, once the saturation slider is moved for the first time,
97
- // editor collapses the selection and doesn't apply the color change.
98
- // See: https://github.com/cksource/ckeditor5-internal/issues/3245, https://github.com/ckeditor/ckeditor5/issues/14119,
99
- // https://github.com/cksource/ckeditor5-internal/issues/3268.
100
- /* istanbul ignore next -- @preserve */
101
- if (env.isGecko || env.isiOS || env.isSafari) {
102
- const input = this.hexInputRow.children.get(1);
103
- input.focus();
104
- }
105
- const firstSlider = this.slidersView.first;
106
- firstSlider.focus();
107
- }
108
- /**
109
- * Creates collection of sliders in color picker.
110
- *
111
- * @private
112
- */
113
- _createSlidersView() {
114
- const colorPickersChildren = [...this.picker.shadowRoot.children];
115
- const sliders = colorPickersChildren.filter(item => item.getAttribute('role') === 'slider');
116
- const slidersView = sliders.map(slider => {
117
- const view = new SliderView(slider);
118
- return view;
119
- });
120
- this.slidersView = this.createCollection();
121
- slidersView.forEach(item => {
122
- this.slidersView.add(item);
123
- });
124
- }
125
- /**
126
- * Creates input row for defining custom colors in color picker.
127
- *
128
- * @private
129
- */
130
- _createInputRow() {
131
- const hashView = new HashView();
132
- const colorInput = this._createColorInput();
133
- return new ColorPickerInputRowView(this.locale, [hashView, colorInput]);
134
- }
135
- /**
136
- * Creates the input where user can type or paste the color in hex format.
137
- *
138
- * @private
139
- */
140
- _createColorInput() {
141
- const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);
142
- const { t } = this.locale;
143
- labeledInput.set({
144
- label: t('HEX'),
145
- class: 'color-picker-hex-input'
146
- });
147
- labeledInput.fieldView.bind('value').to(this, '_hexColor', pickerColor => {
148
- if (labeledInput.isFocused) {
149
- // Text field shouldn't be updated with color change if the text field is focused.
150
- // Imagine user typing hex code and getting the value of field changed.
151
- return labeledInput.fieldView.value;
152
- }
153
- else {
154
- return pickerColor.startsWith('#') ? pickerColor.substring(1) : pickerColor;
155
- }
156
- });
157
- // Only accept valid hex colors as input.
158
- labeledInput.fieldView.on('input', () => {
159
- const inputValue = labeledInput.fieldView.element.value;
160
- if (inputValue) {
161
- // Trim the whitespace.
162
- const trimmedValue = inputValue.trim();
163
- // Drop the `#` from the beginning if present.
164
- const hashlessInput = trimmedValue.startsWith('#') ? trimmedValue.substring(1) : trimmedValue;
165
- // Check if it's a hex color (3,4,6 or 8 chars long and with proper characters).
166
- const isValidHexColor = [3, 4, 6, 8].includes(hashlessInput.length) &&
167
- /(([0-9a-fA-F]{2}){3,4}|([0-9a-fA-F]){3,4})/.test(hashlessInput);
168
- if (isValidHexColor) {
169
- // If so, set the color.
170
- // Otherwise, do nothing.
171
- this._debounceColorPickerEvent('#' + hashlessInput);
172
- }
173
- }
174
- });
175
- return labeledInput;
176
- }
177
- }
178
- // Converts any color format to a unified hex format.
179
- //
180
- // @param inputColor
181
- // @returns An unified hex string.
182
- function convertColorToCommonHexFormat(inputColor) {
183
- let ret = convertToHex(inputColor);
184
- if (!ret) {
185
- ret = '#000';
186
- }
187
- if (ret.length === 4) {
188
- // Unfold shortcut format.
189
- ret = '#' + [ret[1], ret[1], ret[2], ret[2], ret[3], ret[3]].join('');
190
- }
191
- return ret.toLowerCase();
192
- }
193
- // View abstraction over pointer in color picker.
194
- class SliderView extends View {
195
- /**
196
- * @param element HTML elemnt of slider in color picker.
197
- */
198
- constructor(element) {
199
- super();
200
- this.element = element;
201
- }
202
- /**
203
- * Focuses element.
204
- */
205
- focus() {
206
- this.element.focus();
207
- }
208
- }
209
- // View abstaction over the `#` character before color input.
210
- class HashView extends View {
211
- constructor(locale) {
212
- super(locale);
213
- this.setTemplate({
214
- tag: 'div',
215
- attributes: {
216
- class: [
217
- 'ck',
218
- 'ck-color-picker__hash-view'
219
- ]
220
- },
221
- children: '#'
222
- });
223
- }
224
- }
225
- // The class representing a row containing hex color input field.
226
- // **Note**: For now this class is private. When more use cases appear (beyond `ckeditor5-table` and `ckeditor5-image`),
227
- // it will become a component in `ckeditor5-ui`.
228
- //
229
- // @private
230
- class ColorPickerInputRowView extends View {
231
- /**
232
- * Creates an instance of the form row class.
233
- *
234
- * @param locale The locale instance.
235
- */
236
- constructor(locale, children) {
237
- super(locale);
238
- this.children = this.createCollection(children);
239
- this.setTemplate({
240
- tag: 'div',
241
- attributes: {
242
- class: [
243
- 'ck',
244
- 'ck-color-picker__row'
245
- ]
246
- },
247
- children: this.children
248
- });
249
- }
250
- }
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 ui/colorpicker/colorpickerview
7
+ */
8
+ import { convertColor, convertToHex } from './utils';
9
+ import { global, env } from '@ckeditor/ckeditor5-utils';
10
+ import { debounce } from 'lodash-es';
11
+ import View from '../view';
12
+ import LabeledFieldView from '../labeledfield/labeledfieldview';
13
+ import { createLabeledInputText } from '../labeledfield/utils';
14
+ import 'vanilla-colorful/hex-color-picker.js';
15
+ import '../../theme/components/colorpicker/colorpicker.css';
16
+ const waitingTime = 150;
17
+ export default class ColorPickerView extends View {
18
+ /**
19
+ * Creates a view of color picker.
20
+ *
21
+ * @param locale
22
+ * @param config
23
+ */
24
+ constructor(locale, config) {
25
+ super(locale);
26
+ this.set('color', '');
27
+ this.set('_hexColor', '');
28
+ this._format = config.format || 'hsl';
29
+ this.hexInputRow = this._createInputRow();
30
+ const children = this.createCollection();
31
+ children.add(this.hexInputRow);
32
+ this.setTemplate({
33
+ tag: 'div',
34
+ attributes: {
35
+ class: ['ck', 'ck-color-picker'],
36
+ tabindex: -1
37
+ },
38
+ children
39
+ });
40
+ this._debounceColorPickerEvent = debounce((color) => {
41
+ this.set('color', color);
42
+ }, waitingTime, {
43
+ leading: true
44
+ });
45
+ // Sets color in the picker if color was updated.
46
+ this.on('set:color', (evt, propertyName, newValue) => {
47
+ // The color needs always to be kept in the output format.
48
+ evt.return = convertColor(newValue, this._format);
49
+ });
50
+ this.on('change:color', () => {
51
+ this._hexColor = convertColorToCommonHexFormat(this.color);
52
+ });
53
+ this.on('change:_hexColor', () => {
54
+ // Should update color in color picker when its not focused
55
+ if (document.activeElement !== this.picker) {
56
+ this.picker.setAttribute('color', this._hexColor);
57
+ }
58
+ // There has to be two way binding between properties.
59
+ // Extra precaution has to be taken to trigger change back only when the color really changes.
60
+ if (convertColorToCommonHexFormat(this.color) != convertColorToCommonHexFormat(this._hexColor)) {
61
+ this.color = this._hexColor;
62
+ }
63
+ });
64
+ }
65
+ /**
66
+ * Renders color picker in the view.
67
+ */
68
+ render() {
69
+ super.render();
70
+ this.picker = global.document.createElement('hex-color-picker');
71
+ this.picker.setAttribute('class', 'hex-color-picker');
72
+ this.picker.setAttribute('tabindex', '-1');
73
+ this._createSlidersView();
74
+ if (this.element) {
75
+ this.element.insertBefore(this.picker, this.hexInputRow.element);
76
+ // Create custom stylesheet with a look of focused pointer in color picker and append it into the color picker shadowDom
77
+ const styleSheetForFocusedColorPicker = document.createElement('style');
78
+ styleSheetForFocusedColorPicker.textContent = '[role="slider"]:focus [part$="pointer"] {' +
79
+ 'border: 1px solid #fff;' +
80
+ 'outline: 1px solid var(--ck-color-focus-border);' +
81
+ 'box-shadow: 0 0 0 2px #fff;' +
82
+ '}';
83
+ this.picker.shadowRoot.appendChild(styleSheetForFocusedColorPicker);
84
+ }
85
+ this.picker.addEventListener('color-changed', event => {
86
+ const customEvent = event;
87
+ const color = customEvent.detail.value;
88
+ this._debounceColorPickerEvent(color);
89
+ });
90
+ }
91
+ /**
92
+ * Focuses the first pointer in color picker.
93
+ *
94
+ */
95
+ focus() {
96
+ // In some browsers we need to move the focus to the input first.
97
+ // Otherwise, the color picker doesn't behave as expected.
98
+ // In FF, after selecting the color via slider, it instantly moves back to the previous color.
99
+ // In all iOS browsers and desktop Safari, once the saturation slider is moved for the first time,
100
+ // editor collapses the selection and doesn't apply the color change.
101
+ // See: https://github.com/cksource/ckeditor5-internal/issues/3245, https://github.com/ckeditor/ckeditor5/issues/14119,
102
+ // https://github.com/cksource/ckeditor5-internal/issues/3268.
103
+ /* istanbul ignore next -- @preserve */
104
+ if (env.isGecko || env.isiOS || env.isSafari) {
105
+ const input = this.hexInputRow.children.get(1);
106
+ input.focus();
107
+ }
108
+ const firstSlider = this.slidersView.first;
109
+ firstSlider.focus();
110
+ }
111
+ /**
112
+ * Creates collection of sliders in color picker.
113
+ *
114
+ * @private
115
+ */
116
+ _createSlidersView() {
117
+ const colorPickersChildren = [...this.picker.shadowRoot.children];
118
+ const sliders = colorPickersChildren.filter(item => item.getAttribute('role') === 'slider');
119
+ const slidersView = sliders.map(slider => {
120
+ const view = new SliderView(slider);
121
+ return view;
122
+ });
123
+ this.slidersView = this.createCollection();
124
+ slidersView.forEach(item => {
125
+ this.slidersView.add(item);
126
+ });
127
+ }
128
+ /**
129
+ * Creates input row for defining custom colors in color picker.
130
+ *
131
+ * @private
132
+ */
133
+ _createInputRow() {
134
+ const hashView = new HashView();
135
+ const colorInput = this._createColorInput();
136
+ return new ColorPickerInputRowView(this.locale, [hashView, colorInput]);
137
+ }
138
+ /**
139
+ * Creates the input where user can type or paste the color in hex format.
140
+ *
141
+ * @private
142
+ */
143
+ _createColorInput() {
144
+ const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);
145
+ const { t } = this.locale;
146
+ labeledInput.set({
147
+ label: t('HEX'),
148
+ class: 'color-picker-hex-input'
149
+ });
150
+ labeledInput.fieldView.bind('value').to(this, '_hexColor', pickerColor => {
151
+ if (labeledInput.isFocused) {
152
+ // Text field shouldn't be updated with color change if the text field is focused.
153
+ // Imagine user typing hex code and getting the value of field changed.
154
+ return labeledInput.fieldView.value;
155
+ }
156
+ else {
157
+ return pickerColor.startsWith('#') ? pickerColor.substring(1) : pickerColor;
158
+ }
159
+ });
160
+ // Only accept valid hex colors as input.
161
+ labeledInput.fieldView.on('input', () => {
162
+ const inputValue = labeledInput.fieldView.element.value;
163
+ if (inputValue) {
164
+ // Trim the whitespace.
165
+ const trimmedValue = inputValue.trim();
166
+ // Drop the `#` from the beginning if present.
167
+ const hashlessInput = trimmedValue.startsWith('#') ? trimmedValue.substring(1) : trimmedValue;
168
+ // Check if it's a hex color (3,4,6 or 8 chars long and with proper characters).
169
+ const isValidHexColor = [3, 4, 6, 8].includes(hashlessInput.length) &&
170
+ /(([0-9a-fA-F]{2}){3,4}|([0-9a-fA-F]){3,4})/.test(hashlessInput);
171
+ if (isValidHexColor) {
172
+ // If so, set the color.
173
+ // Otherwise, do nothing.
174
+ this._debounceColorPickerEvent('#' + hashlessInput);
175
+ }
176
+ }
177
+ });
178
+ return labeledInput;
179
+ }
180
+ }
181
+ // Converts any color format to a unified hex format.
182
+ //
183
+ // @param inputColor
184
+ // @returns An unified hex string.
185
+ function convertColorToCommonHexFormat(inputColor) {
186
+ let ret = convertToHex(inputColor);
187
+ if (!ret) {
188
+ ret = '#000';
189
+ }
190
+ if (ret.length === 4) {
191
+ // Unfold shortcut format.
192
+ ret = '#' + [ret[1], ret[1], ret[2], ret[2], ret[3], ret[3]].join('');
193
+ }
194
+ return ret.toLowerCase();
195
+ }
196
+ // View abstraction over pointer in color picker.
197
+ class SliderView extends View {
198
+ /**
199
+ * @param element HTML elemnt of slider in color picker.
200
+ */
201
+ constructor(element) {
202
+ super();
203
+ this.element = element;
204
+ }
205
+ /**
206
+ * Focuses element.
207
+ */
208
+ focus() {
209
+ this.element.focus();
210
+ }
211
+ }
212
+ // View abstaction over the `#` character before color input.
213
+ class HashView extends View {
214
+ constructor(locale) {
215
+ super(locale);
216
+ this.setTemplate({
217
+ tag: 'div',
218
+ attributes: {
219
+ class: [
220
+ 'ck',
221
+ 'ck-color-picker__hash-view'
222
+ ]
223
+ },
224
+ children: '#'
225
+ });
226
+ }
227
+ }
228
+ // The class representing a row containing hex color input field.
229
+ // **Note**: For now this class is private. When more use cases appear (beyond `ckeditor5-table` and `ckeditor5-image`),
230
+ // it will become a component in `ckeditor5-ui`.
231
+ //
232
+ // @private
233
+ class ColorPickerInputRowView extends View {
234
+ /**
235
+ * Creates an instance of the form row class.
236
+ *
237
+ * @param locale The locale instance.
238
+ */
239
+ constructor(locale, children) {
240
+ super(locale);
241
+ this.children = this.createCollection(children);
242
+ this.setTemplate({
243
+ tag: 'div',
244
+ attributes: {
245
+ class: [
246
+ 'ck',
247
+ 'ck-color-picker__row'
248
+ ]
249
+ },
250
+ children: this.children
251
+ });
252
+ }
253
+ }
@@ -1,35 +1,35 @@
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
- * Color formats handled by color converter.
7
- */
8
- export type ColorPickerOutputFormat = 'hex' | 'rgb' | 'hsl' | 'hwb' | 'lab' | 'lch';
9
- /**
10
- * Configuration of the color picker feature.
11
- *
12
- * It can be forced to apply colors in the editor in a particular format.
13
- *
14
- * @default `{
15
- * format: 'hsl'
16
- * }`
17
- */
18
- export type ColorPickerConfig = {
19
- format?: ColorPickerOutputFormat;
20
- };
21
- /**
22
- * Parses and converts the color string to requested format. Handles variety of color spaces
23
- * like `hsl`, `hex` or `rgb`.
24
- *
25
- * @param color
26
- * @returns A color string.
27
- */
28
- export declare function convertColor(color: string, outputFormat: ColorPickerOutputFormat): string;
29
- /**
30
- * Converts a color string to hex format.
31
- *
32
- * @param color
33
- * @returns A color string.
34
- */
35
- export declare function convertToHex(color: string): string;
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
+ * Color formats handled by color converter.
7
+ */
8
+ export type ColorPickerOutputFormat = 'hex' | 'rgb' | 'hsl' | 'hwb' | 'lab' | 'lch';
9
+ /**
10
+ * Configuration of the color picker feature.
11
+ *
12
+ * It can be forced to apply colors in the editor in a particular format.
13
+ *
14
+ * @default `{
15
+ * format: 'hsl'
16
+ * }`
17
+ */
18
+ export type ColorPickerConfig = {
19
+ format?: ColorPickerOutputFormat;
20
+ };
21
+ /**
22
+ * Parses and converts the color string to requested format. Handles variety of color spaces
23
+ * like `hsl`, `hex` or `rgb`.
24
+ *
25
+ * @param color
26
+ * @returns A color string.
27
+ */
28
+ export declare function convertColor(color: string, outputFormat: ColorPickerOutputFormat): string;
29
+ /**
30
+ * Converts a color string to hex format.
31
+ *
32
+ * @param color
33
+ * @returns A color string.
34
+ */
35
+ export declare function convertToHex(color: string): string;