@ckeditor/ckeditor5-ui 38.1.0 → 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 (123) hide show
  1. package/package.json +3 -3
  2. package/src/augmentation.d.ts +86 -86
  3. package/src/augmentation.js +5 -5
  4. package/src/bindings/addkeyboardhandlingforgrid.d.ts +27 -27
  5. package/src/bindings/addkeyboardhandlingforgrid.js +107 -107
  6. package/src/bindings/clickoutsidehandler.d.ts +28 -28
  7. package/src/bindings/clickoutsidehandler.js +36 -36
  8. package/src/bindings/csstransitiondisablermixin.d.ts +40 -40
  9. package/src/bindings/csstransitiondisablermixin.js +55 -55
  10. package/src/bindings/injectcsstransitiondisabler.d.ts +59 -59
  11. package/src/bindings/injectcsstransitiondisabler.js +71 -71
  12. package/src/bindings/preventdefault.d.ts +33 -33
  13. package/src/bindings/preventdefault.js +34 -34
  14. package/src/bindings/submithandler.d.ts +57 -57
  15. package/src/bindings/submithandler.js +47 -47
  16. package/src/button/button.d.ts +178 -178
  17. package/src/button/button.js +5 -5
  18. package/src/button/buttonview.d.ts +177 -177
  19. package/src/button/buttonview.js +231 -231
  20. package/src/button/switchbuttonview.d.ts +45 -45
  21. package/src/button/switchbuttonview.js +75 -75
  22. package/src/colorgrid/colorgridview.d.ts +132 -132
  23. package/src/colorgrid/colorgridview.js +124 -124
  24. package/src/colorgrid/colortileview.d.ts +28 -28
  25. package/src/colorgrid/colortileview.js +40 -40
  26. package/src/colorgrid/utils.d.ts +47 -47
  27. package/src/colorgrid/utils.js +84 -84
  28. package/src/colorpicker/colorpickerview.d.ts +110 -110
  29. package/src/colorpicker/colorpickerview.js +253 -253
  30. package/src/colorpicker/utils.d.ts +35 -35
  31. package/src/colorpicker/utils.js +99 -99
  32. package/src/componentfactory.d.ts +81 -81
  33. package/src/componentfactory.js +104 -104
  34. package/src/dropdown/button/dropdownbutton.d.ts +25 -25
  35. package/src/dropdown/button/dropdownbutton.js +5 -5
  36. package/src/dropdown/button/dropdownbuttonview.d.ts +48 -48
  37. package/src/dropdown/button/dropdownbuttonview.js +66 -66
  38. package/src/dropdown/button/splitbuttonview.d.ts +161 -161
  39. package/src/dropdown/button/splitbuttonview.js +152 -152
  40. package/src/dropdown/dropdownpanelfocusable.d.ts +21 -21
  41. package/src/dropdown/dropdownpanelfocusable.js +5 -5
  42. package/src/dropdown/dropdownpanelview.d.ts +62 -62
  43. package/src/dropdown/dropdownpanelview.js +96 -96
  44. package/src/dropdown/dropdownview.d.ts +315 -315
  45. package/src/dropdown/dropdownview.js +378 -378
  46. package/src/dropdown/utils.d.ts +221 -221
  47. package/src/dropdown/utils.js +434 -434
  48. package/src/editableui/editableuiview.d.ts +72 -72
  49. package/src/editableui/editableuiview.js +112 -112
  50. package/src/editableui/inline/inlineeditableuiview.d.ts +40 -40
  51. package/src/editableui/inline/inlineeditableuiview.js +48 -48
  52. package/src/editorui/bodycollection.d.ts +55 -55
  53. package/src/editorui/bodycollection.js +84 -84
  54. package/src/editorui/boxed/boxededitoruiview.d.ts +40 -40
  55. package/src/editorui/boxed/boxededitoruiview.js +81 -81
  56. package/src/editorui/editorui.d.ts +282 -282
  57. package/src/editorui/editorui.js +410 -410
  58. package/src/editorui/editoruiview.d.ts +39 -39
  59. package/src/editorui/editoruiview.js +38 -38
  60. package/src/editorui/poweredby.d.ts +71 -71
  61. package/src/editorui/poweredby.js +294 -294
  62. package/src/focuscycler.d.ts +183 -183
  63. package/src/focuscycler.js +220 -220
  64. package/src/formheader/formheaderview.d.ts +53 -53
  65. package/src/formheader/formheaderview.js +63 -63
  66. package/src/icon/iconview.d.ts +78 -78
  67. package/src/icon/iconview.js +112 -112
  68. package/src/iframe/iframeview.d.ts +50 -50
  69. package/src/iframe/iframeview.js +63 -63
  70. package/src/index.d.ts +62 -62
  71. package/src/index.js +61 -61
  72. package/src/input/inputview.d.ts +121 -121
  73. package/src/input/inputview.js +106 -106
  74. package/src/inputnumber/inputnumberview.d.ts +49 -49
  75. package/src/inputnumber/inputnumberview.js +40 -40
  76. package/src/inputtext/inputtextview.d.ts +18 -18
  77. package/src/inputtext/inputtextview.js +27 -27
  78. package/src/label/labelview.d.ts +36 -36
  79. package/src/label/labelview.js +41 -41
  80. package/src/labeledfield/labeledfieldview.d.ts +182 -182
  81. package/src/labeledfield/labeledfieldview.js +157 -157
  82. package/src/labeledfield/utils.d.ts +93 -93
  83. package/src/labeledfield/utils.js +131 -131
  84. package/src/labeledinput/labeledinputview.d.ts +125 -125
  85. package/src/labeledinput/labeledinputview.js +125 -125
  86. package/src/list/listitemview.d.ts +35 -35
  87. package/src/list/listitemview.js +40 -40
  88. package/src/list/listseparatorview.d.ts +18 -18
  89. package/src/list/listseparatorview.js +28 -28
  90. package/src/list/listview.d.ts +65 -65
  91. package/src/list/listview.js +90 -90
  92. package/src/model.d.ts +22 -22
  93. package/src/model.js +31 -31
  94. package/src/notification/notification.d.ts +211 -211
  95. package/src/notification/notification.js +187 -187
  96. package/src/panel/balloon/balloonpanelview.d.ts +685 -685
  97. package/src/panel/balloon/balloonpanelview.js +988 -988
  98. package/src/panel/balloon/contextualballoon.d.ts +299 -299
  99. package/src/panel/balloon/contextualballoon.js +572 -572
  100. package/src/panel/sticky/stickypanelview.d.ts +132 -132
  101. package/src/panel/sticky/stickypanelview.js +139 -139
  102. package/src/template.d.ts +942 -942
  103. package/src/template.js +1294 -1294
  104. package/src/toolbar/balloon/balloontoolbar.d.ts +122 -122
  105. package/src/toolbar/balloon/balloontoolbar.js +300 -300
  106. package/src/toolbar/block/blockbuttonview.d.ts +35 -35
  107. package/src/toolbar/block/blockbuttonview.js +41 -41
  108. package/src/toolbar/block/blocktoolbar.d.ts +161 -161
  109. package/src/toolbar/block/blocktoolbar.js +391 -391
  110. package/src/toolbar/normalizetoolbarconfig.d.ts +39 -39
  111. package/src/toolbar/normalizetoolbarconfig.js +51 -51
  112. package/src/toolbar/toolbarlinebreakview.d.ts +18 -18
  113. package/src/toolbar/toolbarlinebreakview.js +28 -28
  114. package/src/toolbar/toolbarseparatorview.d.ts +18 -18
  115. package/src/toolbar/toolbarseparatorview.js +28 -28
  116. package/src/toolbar/toolbarview.d.ts +265 -265
  117. package/src/toolbar/toolbarview.js +717 -717
  118. package/src/tooltipmanager.d.ts +180 -180
  119. package/src/tooltipmanager.js +353 -353
  120. package/src/view.d.ts +422 -422
  121. package/src/view.js +396 -396
  122. package/src/viewcollection.d.ts +139 -139
  123. package/src/viewcollection.js +206 -206
@@ -1,253 +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
- // 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
+ /**
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;