@ckeditor/ckeditor5-image 27.1.0 → 29.2.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 (167) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +3 -3
  3. package/build/image.js +1 -1
  4. package/build/translations/ar.js +1 -0
  5. package/build/translations/ast.js +1 -0
  6. package/build/translations/az.js +1 -0
  7. package/build/translations/bg.js +1 -0
  8. package/build/translations/cs.js +1 -0
  9. package/build/translations/da.js +1 -0
  10. package/build/translations/de-ch.js +1 -0
  11. package/build/translations/de.js +1 -0
  12. package/build/translations/el.js +1 -0
  13. package/build/translations/en-au.js +1 -0
  14. package/build/translations/en-gb.js +1 -0
  15. package/build/translations/eo.js +1 -0
  16. package/build/translations/es.js +1 -0
  17. package/build/translations/et.js +1 -0
  18. package/build/translations/eu.js +1 -0
  19. package/build/translations/fa.js +1 -0
  20. package/build/translations/fi.js +1 -0
  21. package/build/translations/fr.js +1 -0
  22. package/build/translations/gl.js +1 -0
  23. package/build/translations/he.js +1 -0
  24. package/build/translations/hi.js +1 -0
  25. package/build/translations/hr.js +1 -0
  26. package/build/translations/hu.js +1 -0
  27. package/build/translations/id.js +1 -0
  28. package/build/translations/it.js +1 -0
  29. package/build/translations/ja.js +1 -0
  30. package/build/translations/km.js +1 -0
  31. package/build/translations/kn.js +1 -0
  32. package/build/translations/ko.js +1 -0
  33. package/build/translations/ku.js +1 -0
  34. package/build/translations/lt.js +1 -0
  35. package/build/translations/lv.js +1 -0
  36. package/build/translations/nb.js +1 -0
  37. package/build/translations/ne.js +1 -0
  38. package/build/translations/nl.js +1 -0
  39. package/build/translations/no.js +1 -0
  40. package/build/translations/pl.js +1 -0
  41. package/build/translations/pt-br.js +1 -0
  42. package/build/translations/pt.js +1 -0
  43. package/build/translations/ro.js +1 -0
  44. package/build/translations/ru.js +1 -0
  45. package/build/translations/si.js +1 -0
  46. package/build/translations/sk.js +1 -0
  47. package/build/translations/sq.js +1 -0
  48. package/build/translations/sr-latn.js +1 -0
  49. package/build/translations/sr.js +1 -0
  50. package/build/translations/sv.js +1 -0
  51. package/build/translations/th.js +1 -0
  52. package/build/translations/tk.js +1 -0
  53. package/build/translations/tr.js +1 -0
  54. package/build/translations/ug.js +1 -0
  55. package/build/translations/uk.js +1 -0
  56. package/build/translations/vi.js +1 -0
  57. package/build/translations/zh-cn.js +1 -0
  58. package/build/translations/zh.js +1 -0
  59. package/ckeditor5-metadata.json +233 -0
  60. package/lang/contexts.json +3 -0
  61. package/lang/translations/ar.po +12 -0
  62. package/lang/translations/ast.po +12 -0
  63. package/lang/translations/az.po +12 -0
  64. package/lang/translations/bg.po +12 -0
  65. package/lang/translations/cs.po +12 -0
  66. package/lang/translations/da.po +12 -0
  67. package/lang/translations/de-ch.po +113 -0
  68. package/lang/translations/de.po +15 -3
  69. package/lang/translations/el.po +12 -0
  70. package/lang/translations/en-au.po +12 -0
  71. package/lang/translations/en-gb.po +12 -0
  72. package/lang/translations/en.po +12 -0
  73. package/lang/translations/eo.po +12 -0
  74. package/lang/translations/es.po +12 -0
  75. package/lang/translations/et.po +12 -0
  76. package/lang/translations/eu.po +12 -0
  77. package/lang/translations/fa.po +12 -0
  78. package/lang/translations/fi.po +12 -0
  79. package/lang/translations/fr.po +12 -0
  80. package/lang/translations/gl.po +12 -0
  81. package/lang/translations/he.po +12 -0
  82. package/lang/translations/hi.po +12 -0
  83. package/lang/translations/hr.po +12 -0
  84. package/lang/translations/hu.po +13 -1
  85. package/lang/translations/id.po +21 -9
  86. package/lang/translations/it.po +12 -0
  87. package/lang/translations/ja.po +12 -0
  88. package/lang/translations/km.po +12 -0
  89. package/lang/translations/kn.po +12 -0
  90. package/lang/translations/ko.po +12 -0
  91. package/lang/translations/ku.po +12 -0
  92. package/lang/translations/lt.po +12 -0
  93. package/lang/translations/lv.po +12 -0
  94. package/lang/translations/nb.po +12 -0
  95. package/lang/translations/ne.po +12 -0
  96. package/lang/translations/nl.po +12 -0
  97. package/lang/translations/no.po +12 -0
  98. package/lang/translations/pl.po +20 -8
  99. package/lang/translations/pt-br.po +12 -0
  100. package/lang/translations/pt.po +12 -0
  101. package/lang/translations/ro.po +21 -9
  102. package/lang/translations/ru.po +12 -0
  103. package/lang/translations/si.po +12 -0
  104. package/lang/translations/sk.po +12 -0
  105. package/lang/translations/sq.po +12 -0
  106. package/lang/translations/sr-latn.po +12 -0
  107. package/lang/translations/sr.po +12 -0
  108. package/lang/translations/sv.po +12 -0
  109. package/lang/translations/th.po +12 -0
  110. package/lang/translations/tk.po +12 -0
  111. package/lang/translations/tr.po +12 -0
  112. package/lang/translations/ug.po +12 -0
  113. package/lang/translations/uk.po +12 -0
  114. package/lang/translations/vi.po +12 -0
  115. package/lang/translations/zh-cn.po +12 -0
  116. package/lang/translations/zh.po +12 -0
  117. package/package.json +36 -29
  118. package/src/autoimage.js +6 -4
  119. package/src/image/converters.js +192 -13
  120. package/src/image/imageblockediting.js +179 -0
  121. package/src/image/imageediting.js +13 -70
  122. package/src/image/imageinlineediting.js +204 -0
  123. package/src/image/imagetypecommand.js +105 -0
  124. package/src/image/insertimagecommand.js +77 -10
  125. package/src/image/ui/utils.js +3 -3
  126. package/src/image/utils.js +70 -121
  127. package/src/image.js +7 -19
  128. package/src/imageblock.js +46 -0
  129. package/src/imagecaption/imagecaptionediting.js +202 -230
  130. package/src/imagecaption/imagecaptionui.js +78 -0
  131. package/src/imagecaption/toggleimagecaptioncommand.js +165 -0
  132. package/src/imagecaption/utils.js +25 -40
  133. package/src/imagecaption.js +3 -2
  134. package/src/imageinline.js +46 -0
  135. package/src/imageinsert/imageinsertui.js +5 -6
  136. package/src/imageinsert.js +16 -4
  137. package/src/imageresize/imageresizebuttons.js +1 -1
  138. package/src/imageresize/imageresizeediting.js +21 -8
  139. package/src/imageresize/imageresizehandles.js +30 -8
  140. package/src/imageresize/resizeimagecommand.js +8 -5
  141. package/src/imagestyle/converters.js +25 -17
  142. package/src/imagestyle/imagestylecommand.js +73 -33
  143. package/src/imagestyle/imagestyleediting.js +113 -52
  144. package/src/imagestyle/imagestyleui.js +197 -31
  145. package/src/imagestyle/utils.js +300 -85
  146. package/src/imagestyle.js +218 -47
  147. package/src/imagetextalternative/imagetextalternativecommand.js +10 -7
  148. package/src/imagetextalternative/imagetextalternativeediting.js +9 -1
  149. package/src/imagetextalternative/imagetextalternativeui.js +2 -2
  150. package/src/imagetextalternative.js +1 -1
  151. package/src/imagetoolbar.js +33 -11
  152. package/src/imageupload/imageuploadediting.js +91 -31
  153. package/src/imageupload/imageuploadprogress.js +17 -9
  154. package/src/imageupload/imageuploadui.js +1 -1
  155. package/src/imageupload/uploadimagecommand.js +50 -24
  156. package/src/imageupload/utils.js +3 -2
  157. package/src/imageupload.js +1 -1
  158. package/src/imageutils.js +342 -0
  159. package/src/index.js +22 -47
  160. package/src/pictureediting.js +149 -0
  161. package/theme/image.css +101 -21
  162. package/theme/imagecaption.css +24 -2
  163. package/theme/imageresize.css +11 -0
  164. package/theme/imagestyle.css +76 -0
  165. package/theme/imageuploadicon.css +8 -2
  166. package/theme/imageuploadprogress.css +12 -8
  167. package/build/image.js.map +0 -1
package/src/imagestyle.js CHANGED
@@ -14,10 +14,14 @@ import ImageStyleUI from './imagestyle/imagestyleui';
14
14
  /**
15
15
  * The image style plugin.
16
16
  *
17
- * For a detailed overview, check the {@glink features/image#image-styles image styles} documentation.
17
+ * For a detailed overview of the image styles feature, check the {@glink features/images/images-styles documentation}.
18
18
  *
19
- * This is a "glue" plugin which loads the {@link module:image/imagestyle/imagestyleediting~ImageStyleEditing}
20
- * and {@link module:image/imagestyle/imagestyleui~ImageStyleUI} plugins.
19
+ * This is a "glue" plugin which loads the following plugins:
20
+ * * {@link module:image/imagestyle/imagestyleediting~ImageStyleEditing},
21
+ * * {@link module:image/imagestyle/imagestyleui~ImageStyleUI}
22
+ *
23
+ * It provides a default configuration, which can be extended or overwritten.
24
+ * Read more about the {@link module:image/image~ImageConfig#styles image styles configuration}.
21
25
  *
22
26
  * @extends module:core/plugin~Plugin
23
27
  */
@@ -38,76 +42,243 @@ export default class ImageStyle extends Plugin {
38
42
  }
39
43
 
40
44
  /**
41
- * Available image styles.
45
+ * The configuration for the {@link module:image/imagestyle~ImageStyle} plugin that should be provided
46
+ * while creating the editor instance.
47
+ *
48
+ * A detailed information about the default configuration and customization can be found in
49
+ * {@link module:image/image~ImageConfig#styles `ImageConfig#styles`}.
50
+ *
51
+ * @interface ImageStyleConfig
52
+ */
53
+
54
+ /**
55
+ * A list of the image style options.
56
+ *
57
+ * @member {Array.<module:image/imagestyle~ImageStyleOptionDefinition>} module:image/imagestyle~ImageStyleConfig#options
58
+ */
59
+
60
+ /**
61
+ * The {@link module:image/imagestyle `ImageStyle`} plugin requires a list of the
62
+ * {@link module:image/imagestyle~ImageStyleConfig#options image style options} to work properly.
63
+ * The default configuration is provided (listed below) and can be customized while creating the editor instance.
64
+ *
65
+ * # **Command**
66
+ *
67
+ * The {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand `imageStyleCommand`}
68
+ * is configured based on the defined options,
69
+ * so you can change the style of the selected image by executing the following command:
42
70
  *
43
- * The default value is:
71
+ * editor.execute( 'imageStyle' { value: 'alignLeft' } );
44
72
  *
45
- * const imageConfig = {
46
- * styles: [ 'full', 'side' ]
73
+ * # **Buttons**
74
+ *
75
+ * All of the image style options provided in the configuration are registered
76
+ * in the {@link module:ui/componentfactory~ComponentFactory UI components factory} with the "imageStyle:" prefixes and can be used
77
+ * in the {@link module:image/image~ImageConfig#toolbar image toolbar configuration}. The buttons available by default depending
78
+ * on the loaded plugins are listed in the next section.
79
+ *
80
+ * Read more about styling images in the {@glink features/images/images-styles Image styles guide}.
81
+ *
82
+ * # **Default options and buttons**
83
+ *
84
+ * If the custom configuration is not provided, the default configuration will be used depending on the loaded
85
+ * image editing plugins.
86
+ *
87
+ * * If both {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} and
88
+ * {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} plugins are loaded
89
+ * (which is usually the default editor configuration), the following options will be available for the toolbar
90
+ * configuration. These options will be registered as the buttons with the "imageStyle:" prefixes.
91
+ *
92
+ * const imageDefaultConfig = {
93
+ * styles: {
94
+ * options: [
95
+ * 'inline', 'alignLeft', 'alignRight',
96
+ * 'alignCenter', 'alignBlockLeft', 'alignBlockRight',
97
+ * 'block', 'side'
98
+ * ]
99
+ * }
47
100
  * };
48
101
  *
49
- * which configures two default styles:
102
+ * * If only the {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} plugin is loaded,
103
+ * the following buttons (options) and groups will be available for the toolbar configuration.
104
+ * These options will be registered as the buttons with the "imageStyle:" prefixes.
105
+ *
106
+ * const imageDefaultConfig = {
107
+ * styles: {
108
+ * options: [ 'block', 'side' ]
109
+ * }
110
+ * };
111
+ *
112
+ * * If only the {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} plugin is loaded,
113
+ * the following buttons (options) and groups will available for the toolbar configuration.
114
+ * These options will be registered as the buttons with the "imageStyle:" prefixes.
115
+ *
116
+ * const imageDefaultConfig = {
117
+ * styles: {
118
+ * options: [ 'inline', 'alignLeft', 'alignRight' ]
119
+ * }
120
+ * };
50
121
  *
51
- * * the "full" style which does not apply any class, e.g. for images styled to span 100% width of the content,
52
- * * the "side" style with the `.image-style-side` CSS class.
122
+ * Read more about the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default styling options}.
53
123
  *
54
- * See {@link module:image/imagestyle/utils~defaultStyles} to learn more about default
55
- * styles provided by the image feature.
124
+ * # **Custom configuration**
56
125
  *
57
- * The {@link module:image/imagestyle/utils~defaultStyles default styles} can be customized,
58
- * e.g. to change the icon, title or CSS class of the style. The feature also provides several
59
- * {@link module:image/imagestyle/utils~defaultIcons default icons} to choose from.
126
+ * The image styles configuration can be customized in several ways:
127
+ *
128
+ * * Any of the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default styling options}
129
+ * can be loaded by the reference to its name as follows:
130
+ *
131
+ * ClassicEditor
132
+ * .create( editorElement, {
133
+ * image: {
134
+ * styles: {
135
+ * options: [ 'alignLeft', 'alignRight' ]
136
+ * }
137
+ * }
138
+ * } );
139
+ *
140
+ * * Each of the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default image style options} can be customized,
141
+ * e.g. to change the `icon`, `title` or CSS `className` of the style. The feature also provides several
142
+ * {@link module:image/imagestyle/utils~DEFAULT_ICONS default icons} to choose from.
60
143
  *
61
144
  * import customIcon from 'custom-icon.svg';
62
145
  *
63
146
  * // ...
64
147
  *
65
- * const imageConfig = {
66
- * styles: [
67
- * // This will only customize the icon of the "full" style.
68
- * // Note: 'right' is one of default icons provided by the feature.
69
- * { name: 'full', icon: 'right' },
148
+ * ClassicEditor.create( editorElement, { image:
149
+ * styles: {
150
+ * options: {
151
+ * // This will only customize the icon of the "block" style.
152
+ * // Note: 'right' is one of default icons provided by the feature.
153
+ * {
154
+ * name: 'block',
155
+ * icon: 'right'
156
+ * },
70
157
  *
71
- * // This will customize the icon, title and CSS class of the default "side" style.
72
- * { name: 'side', icon: customIcon, title: 'My side style', className: 'custom-side-image' }
73
- * ]
74
- * };
158
+ * // This will customize the icon, title and CSS class of the default "side" style.
159
+ * {
160
+ * name: 'side',
161
+ * icon: customIcon,
162
+ * title: 'My side style',
163
+ * className: 'custom-side-image'
164
+ * }
165
+ * }
166
+ * }
167
+ * } );
75
168
  *
76
- * If none of the default styles is good enough, it is possible to define independent custom styles, too:
169
+ * * If none of the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default image style options}
170
+ * works for the integration, it is possible to define independent custom styles, too.
77
171
  *
78
- * import { icons } from 'ckeditor5/src/core';
172
+ * See the documentation about the image style {@link module:image/imagestyle~ImageStyleOptionDefinition options}
173
+ * to define the custom image style configuration properly.
79
174
  *
80
- * const fullSizeIcon = icons.objectCenter';
81
- * const sideIcon = icons.objectRight';
175
+ * import redIcon from 'red-icon.svg';
176
+ * import blueIcon from 'blue-icon.svg';
82
177
  *
83
178
  * // ...
84
179
  *
85
- * const imageConfig = {
86
- * styles: [
87
- * // A completely custom full size style with no class, used as a default.
88
- * { name: 'fullSize', title: 'Full size', icon: fullSizeIcon, isDefault: true },
180
+ * ClassicEditor.create( editorElement, { image:
181
+ * styles: {
182
+ * // A list of completely custom styling options.
183
+ * options: [
184
+ * {
185
+ * name: 'regular',
186
+ * modelElements: [ 'imageBlock', 'imageInline' ],
187
+ * title: 'Regular image',
188
+ * icon: 'full',
189
+ * isDefault: true
190
+ * }, {
191
+ * name: 'blue',
192
+ * modelElements: [ 'imageInline' ],
193
+ * title: 'Blue image',
194
+ * icon: blueIcon,
195
+ * className: 'image-blue'
196
+ * }, {
197
+ * name: 'red',
198
+ * modelElements: [ 'imageBlock' ],
199
+ * title: 'Red image',
200
+ * icon: redIcon,
201
+ * className: 'image-red'
202
+ * }
203
+ * ]
204
+ * }
205
+ * } );
89
206
  *
90
- * { name: 'side', title: 'To the side', icon: sideIcon, className: 'side-image' }
91
- * ]
92
- * };
207
+ * @member {module:image/imagestyle~ImageStyleConfig} module:image/image~ImageConfig#styles
208
+ */
209
+
210
+ /**
211
+ * The image styling option definition descriptor.
212
+ *
213
+ * This definition should be implemented in the `Image` plugin {@link module:image/image~ImageConfig#styles configuration} for:
214
+ *
215
+ * * customizing one of the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default styling options} by providing the proper name
216
+ * of the default style and the properties that should be overridden,
217
+ * * or defining a completely custom styling option by providing a custom name and implementing the following properties.
218
+ *
219
+ * import fullSizeIcon from 'path/to/icon.svg';
93
220
  *
94
- * Note: Setting `title` to one of {@link module:image/imagestyle/imagestyleui~ImageStyleUI#localizedDefaultStylesTitles}
221
+ * const imageStyleOptionDefinition = {
222
+ * name: 'fullSize',
223
+ * icon: fullSizeIcon,
224
+ * title: 'Full size image',
225
+ * className: 'image-full-size',
226
+ * modelElements: [ 'imageBlock', 'imageInline' ]
227
+ * }
228
+ *
229
+ * The styling option will be registered as the button under the name `'imageStyle:{name}'` in the
230
+ * {@link module:ui/componentfactory~ComponentFactory UI components factory} (this functionality is provided by the
231
+ * {@link module:image/imagestyle/imagestyleui~ImageStyleUI} plugin).
232
+ *
233
+ * @property {String} name The unique name of the styling option. It will be used to:
234
+ *
235
+ * * refer to one of the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default styling options} or define the custom style,
236
+ * * store the chosen style in the model by setting the `imageStyle` attribute of the model image element,
237
+ * * as a value of the {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand#execute `imageStyle` command},
238
+ * * when registering a button for the style in the following manner: (`'imageStyle:{name}'`).
239
+ *
240
+ * @property {Boolean} [isDefault] When set, the style will be used as the default one for the model elements
241
+ * listed in the `modelElements` property. A default style does not apply any CSS class to the view element.
242
+ *
243
+ * If this property is not defined, its value is inherited
244
+ * from the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default styling options} addressed in the name property.
245
+ *
246
+ * @property {String} icon One of the following to be used when creating the styles's button:
247
+ *
248
+ * * an SVG icon source (as an XML string),
249
+ * * one of the keys in {@link module:image/imagestyle/utils~DEFAULT_ICONS} to use one of default icons provided by the plugin.
250
+ *
251
+ * If this property is not defined, its value is inherited
252
+ * from the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default styling options} addressed in the name property.
253
+ *
254
+ * @property {String} title The styles's title. Setting `title` to one of
255
+ * {@link module:image/imagestyle/imagestyleui~ImageStyleUI#localizedDefaultStylesTitles}
95
256
  * will automatically translate it to the language of the editor.
96
257
  *
97
- * Read more about styling images in the {@glink features/image#image-styles Image styles guide}.
258
+ * If this property is not defined, its value is inherited
259
+ * from the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default styling options} addressed in the name property.
98
260
  *
99
- * The feature creates commands based on defined styles, so you can change the style of a selected image by executing
100
- * the following command:
261
+ * @property {String} [className] The CSS class used to represent the style in the view.
262
+ * It should be used only for the non-default styles.
101
263
  *
102
- * editor.execute( 'imageStyle' { value: 'side' } );
264
+ * If this property is not defined, its value is inherited
265
+ * from the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default styling options} addressed in the name property.
103
266
  *
104
- * The feature also creates buttons that execute the commands. So, assuming that you use the
105
- * default image styles setting, you can {@link module:image/image~ImageConfig#toolbar configure the image toolbar}
106
- * (or any other toolbar) to contain these options:
267
+ * @property {Array.<String>} modelElements The list of the names of the model elements that are supported by the style.
268
+ * The possible values are:
269
+ * * `[ 'imageBlock' ]` if the style can be applied to the image type introduced by the
270
+ * {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} plugin,
271
+ * * `[ 'imageInline' ]` if the style can be applied to the image type introduced by the
272
+ * {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} plugin,
273
+ * * `[ 'imageInline', 'imageBlock' ]` if the style can be applied to both image types introduced by the plugins mentioned above.
107
274
  *
108
- * const imageConfig = {
109
- * toolbar: [ 'imageStyle:full', 'imageStyle:side' ]
110
- * };
275
+ * This property determines which model element names work with the style. If the model element name of the currently selected
276
+ * image is different, upon executing the
277
+ * {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand#execute `imageStyle`} command the image type (model element name)
278
+ * will automatically change.
279
+ *
280
+ * If this property is not defined, its value is inherited
281
+ * from the {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default styling options} addressed in the name property.
111
282
  *
112
- * @member {Array.<module:image/imagestyle/imagestyleediting~ImageStyleFormat>} module:image/image~ImageConfig#styles
283
+ * @typedef {Object} module:image/imagestyle~ImageStyleOptionDefinition
113
284
  */
@@ -8,10 +8,9 @@
8
8
  */
9
9
 
10
10
  import { Command } from 'ckeditor5/src/core';
11
- import { isImage } from '../image/utils';
12
11
 
13
12
  /**
14
- * The image text alternative command. It is used to change the `alt` attribute of `<image>` elements.
13
+ * The image text alternative command. It is used to change the `alt` attribute of `<imageBlock>` and `<imageInline>` model elements.
15
14
  *
16
15
  * @extends module:core/command~Command
17
16
  */
@@ -28,11 +27,13 @@ export default class ImageTextAlternativeCommand extends Command {
28
27
  * @inheritDoc
29
28
  */
30
29
  refresh() {
31
- const element = this.editor.model.document.selection.getSelectedElement();
30
+ const editor = this.editor;
31
+ const imageUtils = editor.plugins.get( 'ImageUtils' );
32
+ const element = imageUtils.getClosestSelectedImageElement( this.editor.model.document.selection );
32
33
 
33
- this.isEnabled = isImage( element );
34
+ this.isEnabled = !!element;
34
35
 
35
- if ( isImage( element ) && element.hasAttribute( 'alt' ) ) {
36
+ if ( this.isEnabled && element.hasAttribute( 'alt' ) ) {
36
37
  this.value = element.getAttribute( 'alt' );
37
38
  } else {
38
39
  this.value = false;
@@ -47,8 +48,10 @@ export default class ImageTextAlternativeCommand extends Command {
47
48
  * @param {String} options.newValue The new value of the `alt` attribute to set.
48
49
  */
49
50
  execute( options ) {
50
- const model = this.editor.model;
51
- const imageElement = model.document.selection.getSelectedElement();
51
+ const editor = this.editor;
52
+ const imageUtils = editor.plugins.get( 'ImageUtils' );
53
+ const model = editor.model;
54
+ const imageElement = imageUtils.getClosestSelectedImageElement( model.document.selection );
52
55
 
53
56
  model.change( writer => {
54
57
  writer.setAttribute( 'alt', options.newValue, imageElement );
@@ -7,8 +7,9 @@
7
7
  * @module image/imagetextalternative/imagetextalternativeediting
8
8
  */
9
9
 
10
- import ImageTextAlternativeCommand from './imagetextalternativecommand';
11
10
  import { Plugin } from 'ckeditor5/src/core';
11
+ import ImageTextAlternativeCommand from './imagetextalternativecommand';
12
+ import ImageUtils from '../imageutils';
12
13
 
13
14
  /**
14
15
  * The image text alternative editing plugin.
@@ -18,6 +19,13 @@ import { Plugin } from 'ckeditor5/src/core';
18
19
  * @extends module:core/plugin~Plugin
19
20
  */
20
21
  export default class ImageTextAlternativeEditing extends Plugin {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get requires() {
26
+ return [ ImageUtils ];
27
+ }
28
+
21
29
  /**
22
30
  * @inheritDoc
23
31
  */
@@ -12,7 +12,6 @@ import { ButtonView, ContextualBalloon, clickOutsideHandler } from 'ckeditor5/sr
12
12
 
13
13
  import TextAlternativeFormView from './ui/textalternativeformview';
14
14
  import { repositionContextualBalloon, getBalloonPositionData } from '../image/ui/utils';
15
- import { getSelectedImageWidget } from '../image/utils';
16
15
 
17
16
  /**
18
17
  * The image text alternative UI plugin.
@@ -94,6 +93,7 @@ export default class ImageTextAlternativeUI extends Plugin {
94
93
  const editor = this.editor;
95
94
  const view = editor.editing.view;
96
95
  const viewDocument = view.document;
96
+ const imageUtils = editor.plugins.get( 'ImageUtils' );
97
97
 
98
98
  /**
99
99
  * The contextual balloon plugin instance.
@@ -133,7 +133,7 @@ export default class ImageTextAlternativeUI extends Plugin {
133
133
 
134
134
  // Reposition the balloon or hide the form if an image widget is no longer selected.
135
135
  this.listenTo( editor.ui, 'update', () => {
136
- if ( !getSelectedImageWidget( viewDocument.selection ) ) {
136
+ if ( !imageUtils.getClosestSelectedImageWidget( viewDocument.selection ) ) {
137
137
  this._hideForm( true );
138
138
  } else if ( this._isVisible ) {
139
139
  repositionContextualBalloon( editor );
@@ -14,7 +14,7 @@ import ImageTextAlternativeUI from './imagetextalternative/imagetextalternativeu
14
14
  /**
15
15
  * The image text alternative plugin.
16
16
  *
17
- * For a detailed overview, check the {@glink features/image#image-styles image styles} documentation.
17
+ * For a detailed overview, check the {@glink features/images/images-styles image styles} documentation.
18
18
  *
19
19
  * This is a "glue" plugin which loads the
20
20
  * {@link module:image/imagetextalternative/imagetextalternativeediting~ImageTextAlternativeEditing}
@@ -9,13 +9,13 @@
9
9
 
10
10
  import { Plugin } from 'ckeditor5/src/core';
11
11
  import { WidgetToolbarRepository } from 'ckeditor5/src/widget';
12
-
13
- import { getSelectedImageWidget } from './image/utils';
12
+ import ImageUtils from './imageutils';
13
+ import { isObject } from 'lodash-es';
14
14
 
15
15
  /**
16
16
  * The image toolbar plugin. It creates and manages the image toolbar (the toolbar displayed when an image is selected).
17
17
  *
18
- * For a detailed overview, check the {@glink features/image#image-contextual-toolbar image contextual toolbar} documentation.
18
+ * For an overview, check the {@glink features/images/images-overview#image-contextual-toolbar image contextual toolbar} documentation.
19
19
  *
20
20
  * Instances of toolbar components (e.g. buttons) are created using the editor's
21
21
  * {@link module:ui/componentfactory~ComponentFactory component factory}
@@ -30,7 +30,7 @@ export default class ImageToolbar extends Plugin {
30
30
  * @inheritDoc
31
31
  */
32
32
  static get requires() {
33
- return [ WidgetToolbarRepository ];
33
+ return [ WidgetToolbarRepository, ImageUtils ];
34
34
  }
35
35
 
36
36
  /**
@@ -47,11 +47,12 @@ export default class ImageToolbar extends Plugin {
47
47
  const editor = this.editor;
48
48
  const t = editor.t;
49
49
  const widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
50
+ const imageUtils = editor.plugins.get( 'ImageUtils' );
50
51
 
51
52
  widgetToolbarRepository.register( 'image', {
52
53
  ariaLabel: t( 'Image toolbar' ),
53
- items: editor.config.get( 'image.toolbar' ) || [],
54
- getRelatedElement: getSelectedImageWidget
54
+ items: normalizeDeclarativeConfig( editor.config.get( 'image.toolbar' ) || [] ),
55
+ getRelatedElement: selection => imageUtils.getClosestSelectedImageWidget( selection )
55
56
  } );
56
57
  }
57
58
  }
@@ -64,18 +65,39 @@ export default class ImageToolbar extends Plugin {
64
65
  *
65
66
  * * {@link module:image/imagestyle~ImageStyle} (with a default configuration),
66
67
  * * {@link module:image/imagetextalternative~ImageTextAlternative},
68
+ * * {@link module:image/imagecaption~ImageCaption},
69
+ *
70
+ * the following toolbar items will be available in {@link module:ui/componentfactory~ComponentFactory}:
71
+ * * `'imageTextAlternative'`,
72
+ * * `'toggleImageCaption'`,
73
+ * * {@link module:image/image~ImageConfig#styles buttons provided by the `ImageStyle` plugin},
74
+ * * {@link module:image/imagestyle/utils~DEFAULT_DROPDOWN_DEFINITIONS drop-downs provided by the `ImageStyle` plugin},
67
75
  *
68
- * three toolbar items will be available in {@link module:ui/componentfactory~ComponentFactory}:
69
- * `'imageStyle:full'`, `'imageStyle:side'`, and `'imageTextAlternative'` so you can configure the toolbar like this:
76
+ * so you can configure the toolbar like this:
70
77
  *
71
78
  * const imageConfig = {
72
- * toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
79
+ * toolbar: [
80
+ * 'imageStyle:inline', 'imageStyle:wrapText', 'imageStyle:breakText', '|',
81
+ * 'toggleImageCaption', 'imageTextAlternative'
82
+ * ]
73
83
  * };
74
84
  *
75
- * Of course, the same buttons can also be used in the
76
- * {@link module:core/editor/editorconfig~EditorConfig#toolbar main editor toolbar}.
85
+ * Besides that, the `ImageStyle` plugin allows to define a
86
+ * {@link module:image/imagestyle/imagestyleui~ImageStyleDropdownDefinition custom drop-down} while configuring the toolbar.
87
+ *
88
+ * The same items can also be used in the {@link module:core/editor/editorconfig~EditorConfig#toolbar main editor toolbar}.
77
89
  *
78
90
  * Read more about configuring toolbar in {@link module:core/editor/editorconfig~EditorConfig#toolbar}.
79
91
  *
80
92
  * @member {Array.<String>} module:image/image~ImageConfig#toolbar
81
93
  */
94
+
95
+ // Convert the dropdown definitions to their keys registered in the ComponentFactory.
96
+ // The registration precess should be handled by the plugin which handles the UI of a particular feature.
97
+ //
98
+ // @param {Array.<String|module:image/imagestyle/imagestyleui~ImageStyleDropdownDefinition>} config
99
+ //
100
+ // @returns {Array.<String>}
101
+ function normalizeDeclarativeConfig( config ) {
102
+ return config.map( item => isObject( item ) ? item.name : item );
103
+ }