@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.
- package/LICENSE.md +1 -1
- package/README.md +3 -3
- package/build/image.js +1 -1
- package/build/translations/ar.js +1 -0
- package/build/translations/ast.js +1 -0
- package/build/translations/az.js +1 -0
- package/build/translations/bg.js +1 -0
- package/build/translations/cs.js +1 -0
- package/build/translations/da.js +1 -0
- package/build/translations/de-ch.js +1 -0
- package/build/translations/de.js +1 -0
- package/build/translations/el.js +1 -0
- package/build/translations/en-au.js +1 -0
- package/build/translations/en-gb.js +1 -0
- package/build/translations/eo.js +1 -0
- package/build/translations/es.js +1 -0
- package/build/translations/et.js +1 -0
- package/build/translations/eu.js +1 -0
- package/build/translations/fa.js +1 -0
- package/build/translations/fi.js +1 -0
- package/build/translations/fr.js +1 -0
- package/build/translations/gl.js +1 -0
- package/build/translations/he.js +1 -0
- package/build/translations/hi.js +1 -0
- package/build/translations/hr.js +1 -0
- package/build/translations/hu.js +1 -0
- package/build/translations/id.js +1 -0
- package/build/translations/it.js +1 -0
- package/build/translations/ja.js +1 -0
- package/build/translations/km.js +1 -0
- package/build/translations/kn.js +1 -0
- package/build/translations/ko.js +1 -0
- package/build/translations/ku.js +1 -0
- package/build/translations/lt.js +1 -0
- package/build/translations/lv.js +1 -0
- package/build/translations/nb.js +1 -0
- package/build/translations/ne.js +1 -0
- package/build/translations/nl.js +1 -0
- package/build/translations/no.js +1 -0
- package/build/translations/pl.js +1 -0
- package/build/translations/pt-br.js +1 -0
- package/build/translations/pt.js +1 -0
- package/build/translations/ro.js +1 -0
- package/build/translations/ru.js +1 -0
- package/build/translations/si.js +1 -0
- package/build/translations/sk.js +1 -0
- package/build/translations/sq.js +1 -0
- package/build/translations/sr-latn.js +1 -0
- package/build/translations/sr.js +1 -0
- package/build/translations/sv.js +1 -0
- package/build/translations/th.js +1 -0
- package/build/translations/tk.js +1 -0
- package/build/translations/tr.js +1 -0
- package/build/translations/ug.js +1 -0
- package/build/translations/uk.js +1 -0
- package/build/translations/vi.js +1 -0
- package/build/translations/zh-cn.js +1 -0
- package/build/translations/zh.js +1 -0
- package/ckeditor5-metadata.json +233 -0
- package/lang/contexts.json +3 -0
- package/lang/translations/ar.po +12 -0
- package/lang/translations/ast.po +12 -0
- package/lang/translations/az.po +12 -0
- package/lang/translations/bg.po +12 -0
- package/lang/translations/cs.po +12 -0
- package/lang/translations/da.po +12 -0
- package/lang/translations/de-ch.po +113 -0
- package/lang/translations/de.po +15 -3
- package/lang/translations/el.po +12 -0
- package/lang/translations/en-au.po +12 -0
- package/lang/translations/en-gb.po +12 -0
- package/lang/translations/en.po +12 -0
- package/lang/translations/eo.po +12 -0
- package/lang/translations/es.po +12 -0
- package/lang/translations/et.po +12 -0
- package/lang/translations/eu.po +12 -0
- package/lang/translations/fa.po +12 -0
- package/lang/translations/fi.po +12 -0
- package/lang/translations/fr.po +12 -0
- package/lang/translations/gl.po +12 -0
- package/lang/translations/he.po +12 -0
- package/lang/translations/hi.po +12 -0
- package/lang/translations/hr.po +12 -0
- package/lang/translations/hu.po +13 -1
- package/lang/translations/id.po +21 -9
- package/lang/translations/it.po +12 -0
- package/lang/translations/ja.po +12 -0
- package/lang/translations/km.po +12 -0
- package/lang/translations/kn.po +12 -0
- package/lang/translations/ko.po +12 -0
- package/lang/translations/ku.po +12 -0
- package/lang/translations/lt.po +12 -0
- package/lang/translations/lv.po +12 -0
- package/lang/translations/nb.po +12 -0
- package/lang/translations/ne.po +12 -0
- package/lang/translations/nl.po +12 -0
- package/lang/translations/no.po +12 -0
- package/lang/translations/pl.po +20 -8
- package/lang/translations/pt-br.po +12 -0
- package/lang/translations/pt.po +12 -0
- package/lang/translations/ro.po +21 -9
- package/lang/translations/ru.po +12 -0
- package/lang/translations/si.po +12 -0
- package/lang/translations/sk.po +12 -0
- package/lang/translations/sq.po +12 -0
- package/lang/translations/sr-latn.po +12 -0
- package/lang/translations/sr.po +12 -0
- package/lang/translations/sv.po +12 -0
- package/lang/translations/th.po +12 -0
- package/lang/translations/tk.po +12 -0
- package/lang/translations/tr.po +12 -0
- package/lang/translations/ug.po +12 -0
- package/lang/translations/uk.po +12 -0
- package/lang/translations/vi.po +12 -0
- package/lang/translations/zh-cn.po +12 -0
- package/lang/translations/zh.po +12 -0
- package/package.json +36 -29
- package/src/autoimage.js +6 -4
- package/src/image/converters.js +192 -13
- package/src/image/imageblockediting.js +179 -0
- package/src/image/imageediting.js +13 -70
- package/src/image/imageinlineediting.js +204 -0
- package/src/image/imagetypecommand.js +105 -0
- package/src/image/insertimagecommand.js +77 -10
- package/src/image/ui/utils.js +3 -3
- package/src/image/utils.js +70 -121
- package/src/image.js +7 -19
- package/src/imageblock.js +46 -0
- package/src/imagecaption/imagecaptionediting.js +202 -230
- package/src/imagecaption/imagecaptionui.js +78 -0
- package/src/imagecaption/toggleimagecaptioncommand.js +165 -0
- package/src/imagecaption/utils.js +25 -40
- package/src/imagecaption.js +3 -2
- package/src/imageinline.js +46 -0
- package/src/imageinsert/imageinsertui.js +5 -6
- package/src/imageinsert.js +16 -4
- package/src/imageresize/imageresizebuttons.js +1 -1
- package/src/imageresize/imageresizeediting.js +21 -8
- package/src/imageresize/imageresizehandles.js +30 -8
- package/src/imageresize/resizeimagecommand.js +8 -5
- package/src/imagestyle/converters.js +25 -17
- package/src/imagestyle/imagestylecommand.js +73 -33
- package/src/imagestyle/imagestyleediting.js +113 -52
- package/src/imagestyle/imagestyleui.js +197 -31
- package/src/imagestyle/utils.js +300 -85
- package/src/imagestyle.js +218 -47
- package/src/imagetextalternative/imagetextalternativecommand.js +10 -7
- package/src/imagetextalternative/imagetextalternativeediting.js +9 -1
- package/src/imagetextalternative/imagetextalternativeui.js +2 -2
- package/src/imagetextalternative.js +1 -1
- package/src/imagetoolbar.js +33 -11
- package/src/imageupload/imageuploadediting.js +91 -31
- package/src/imageupload/imageuploadprogress.js +17 -9
- package/src/imageupload/imageuploadui.js +1 -1
- package/src/imageupload/uploadimagecommand.js +50 -24
- package/src/imageupload/utils.js +3 -2
- package/src/imageupload.js +1 -1
- package/src/imageutils.js +342 -0
- package/src/index.js +22 -47
- package/src/pictureediting.js +149 -0
- package/theme/image.css +101 -21
- package/theme/imagecaption.css +24 -2
- package/theme/imageresize.css +11 -0
- package/theme/imagestyle.css +76 -0
- package/theme/imageuploadicon.css +8 -2
- package/theme/imageuploadprogress.css +12 -8
- package/build/image.js.map +0 -1
package/src/imagestyle/utils.js
CHANGED
|
@@ -7,145 +7,360 @@
|
|
|
7
7
|
* @module image/imagestyle/utils
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { logWarning } from 'ckeditor5/src/utils';
|
|
11
10
|
import { icons } from 'ckeditor5/src/core';
|
|
11
|
+
import { logWarning } from 'ckeditor5/src/utils';
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
objectFullWidth,
|
|
15
|
+
objectInline,
|
|
16
|
+
objectLeft, objectRight, objectCenter,
|
|
17
|
+
objectBlockLeft, objectBlockRight
|
|
18
|
+
} = icons;
|
|
12
19
|
|
|
13
20
|
/**
|
|
14
|
-
* Default image
|
|
15
|
-
*
|
|
21
|
+
* Default image style options provided by the plugin that can be referred in the {@link module:image/image~ImageConfig#styles}
|
|
22
|
+
* configuration.
|
|
16
23
|
*
|
|
17
|
-
*
|
|
24
|
+
* There are available 5 styles focused on formatting:
|
|
18
25
|
*
|
|
19
|
-
* *
|
|
20
|
-
* *
|
|
26
|
+
* * **`'alignLeft'`** aligns the inline or block image to the left and wraps it with the text using the `image-style-align-left` class,
|
|
27
|
+
* * **`'alignRight'`** aligns the inline or block image to the right and wraps it with the text using the `image-style-align-right` class,
|
|
28
|
+
* * **`'alignCenter'`** centers the block image using the `image-style-align-center` class,
|
|
29
|
+
* * **`'alignBlockLeft'`** aligns the block image to the left using the `image-style-block-align-left` class,
|
|
30
|
+
* * **`'alignBlockRight'`** aligns the block image to the right using the `image-style-block-align-right` class,
|
|
21
31
|
*
|
|
22
|
-
*
|
|
32
|
+
* and 3 semantic styles:
|
|
23
33
|
*
|
|
24
|
-
* *
|
|
25
|
-
* *
|
|
26
|
-
* *
|
|
34
|
+
* * **`'inline'`** is an inline image without any CSS class,
|
|
35
|
+
* * **`'block'`** is a block image without any CSS class,
|
|
36
|
+
* * **`'side'`** is a block image styled with the `image-style-side` CSS class.
|
|
27
37
|
*
|
|
28
|
-
* @
|
|
38
|
+
* @readonly
|
|
39
|
+
* @type {Object.<String,module:image/imagestyle~ImageStyleOptionDefinition>}
|
|
29
40
|
*/
|
|
30
|
-
const
|
|
31
|
-
// This
|
|
32
|
-
|
|
33
|
-
name: '
|
|
34
|
-
title: '
|
|
35
|
-
icon:
|
|
41
|
+
const DEFAULT_OPTIONS = {
|
|
42
|
+
// This style represents an image placed in the line of text.
|
|
43
|
+
inline: {
|
|
44
|
+
name: 'inline',
|
|
45
|
+
title: 'In line',
|
|
46
|
+
icon: objectInline,
|
|
47
|
+
modelElements: [ 'imageInline' ],
|
|
36
48
|
isDefault: true
|
|
37
49
|
},
|
|
38
50
|
|
|
39
|
-
// This represents
|
|
40
|
-
side: {
|
|
41
|
-
name: 'side',
|
|
42
|
-
title: 'Side image',
|
|
43
|
-
icon: icons.objectRight,
|
|
44
|
-
className: 'image-style-side'
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
// This style represents an image aligned to the left.
|
|
51
|
+
// This style represents an image aligned to the left and wrapped with text.
|
|
48
52
|
alignLeft: {
|
|
49
53
|
name: 'alignLeft',
|
|
50
54
|
title: 'Left aligned image',
|
|
51
|
-
icon:
|
|
55
|
+
icon: objectLeft,
|
|
56
|
+
modelElements: [ 'imageBlock', 'imageInline' ],
|
|
52
57
|
className: 'image-style-align-left'
|
|
53
58
|
},
|
|
54
59
|
|
|
60
|
+
// This style represents an image aligned to the left.
|
|
61
|
+
alignBlockLeft: {
|
|
62
|
+
name: 'alignBlockLeft',
|
|
63
|
+
title: 'Left aligned image',
|
|
64
|
+
icon: objectBlockLeft,
|
|
65
|
+
modelElements: [ 'imageBlock' ],
|
|
66
|
+
className: 'image-style-block-align-left'
|
|
67
|
+
},
|
|
68
|
+
|
|
55
69
|
// This style represents a centered image.
|
|
56
70
|
alignCenter: {
|
|
57
71
|
name: 'alignCenter',
|
|
58
72
|
title: 'Centered image',
|
|
59
|
-
icon:
|
|
73
|
+
icon: objectCenter,
|
|
74
|
+
modelElements: [ 'imageBlock' ],
|
|
60
75
|
className: 'image-style-align-center'
|
|
61
76
|
},
|
|
62
77
|
|
|
63
|
-
// This style represents an image aligned to the right.
|
|
78
|
+
// This style represents an image aligned to the right and wrapped with text.
|
|
64
79
|
alignRight: {
|
|
65
80
|
name: 'alignRight',
|
|
66
81
|
title: 'Right aligned image',
|
|
67
|
-
icon:
|
|
82
|
+
icon: objectRight,
|
|
83
|
+
modelElements: [ 'imageBlock', 'imageInline' ],
|
|
68
84
|
className: 'image-style-align-right'
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
// This style represents an image aligned to the right.
|
|
88
|
+
alignBlockRight: {
|
|
89
|
+
name: 'alignBlockRight',
|
|
90
|
+
title: 'Right aligned image',
|
|
91
|
+
icon: objectBlockRight,
|
|
92
|
+
modelElements: [ 'imageBlock' ],
|
|
93
|
+
className: 'image-style-block-align-right'
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
// This option is equal to the situation when no style is applied.
|
|
97
|
+
block: {
|
|
98
|
+
name: 'block',
|
|
99
|
+
title: 'Centered image',
|
|
100
|
+
icon: objectCenter,
|
|
101
|
+
modelElements: [ 'imageBlock' ],
|
|
102
|
+
isDefault: true
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// This represents a side image.
|
|
106
|
+
side: {
|
|
107
|
+
name: 'side',
|
|
108
|
+
title: 'Side image',
|
|
109
|
+
icon: objectRight,
|
|
110
|
+
modelElements: [ 'imageBlock' ],
|
|
111
|
+
className: 'image-style-side'
|
|
69
112
|
}
|
|
70
113
|
};
|
|
71
114
|
|
|
72
115
|
/**
|
|
73
|
-
* Default image style icons provided by the plugin that can be referred in the
|
|
74
|
-
*
|
|
116
|
+
* Default image style icons provided by the plugin that can be referred in the {@link module:image/image~ImageConfig#styles}
|
|
117
|
+
* configuration.
|
|
118
|
+
*
|
|
119
|
+
* See {@link module:image/imagestyle~ImageStyleOptionDefinition#icon} to learn more.
|
|
75
120
|
*
|
|
76
|
-
* There are
|
|
121
|
+
* There are 7 default icons available: `'full'`, `'left'`, `'inlineLeft'`, `'center'`, `'right'`, `'inlineRight'`, and `'inline'`.
|
|
77
122
|
*
|
|
78
|
-
* @
|
|
123
|
+
* @readonly
|
|
124
|
+
* @type {Object.<String,String>}
|
|
79
125
|
*/
|
|
80
|
-
const
|
|
81
|
-
full:
|
|
82
|
-
left:
|
|
83
|
-
right:
|
|
84
|
-
center:
|
|
126
|
+
const DEFAULT_ICONS = {
|
|
127
|
+
full: objectFullWidth,
|
|
128
|
+
left: objectBlockLeft,
|
|
129
|
+
right: objectBlockRight,
|
|
130
|
+
center: objectCenter,
|
|
131
|
+
inlineLeft: objectLeft,
|
|
132
|
+
inlineRight: objectRight,
|
|
133
|
+
inline: objectInline
|
|
85
134
|
};
|
|
86
135
|
|
|
87
136
|
/**
|
|
88
|
-
*
|
|
89
|
-
* {@link module:image/imagestyle
|
|
137
|
+
* Default drop-downs provided by the plugin that can be referred in the {@link module:image/image~ImageConfig#toolbar}
|
|
138
|
+
* configuration. The drop-downs are containers for the {@link module:image/imagestyle~ImageStyleConfig#options image style options}.
|
|
139
|
+
*
|
|
140
|
+
* If both of the `ImageEditing` plugins are loaded, there are 2 predefined drop-downs available:
|
|
90
141
|
*
|
|
91
|
-
*
|
|
142
|
+
* * **`'imageStyle:wrapText'`**, which contains the `alignLeft` and `alignRight` options, that is,
|
|
143
|
+
* those that wraps the text around the image,
|
|
144
|
+
* * **`'imageStyle:breakText'`**, which contains the `alignBlockLeft`, `alignCenter` and `alignBlockRight` options, that is,
|
|
145
|
+
* those that breaks the text around the image.
|
|
146
|
+
*
|
|
147
|
+
* @readonly
|
|
148
|
+
* @type {Array.<module:image/imagestyle/imagestyleui~ImageStyleDropdownDefinition>}
|
|
149
|
+
*/
|
|
150
|
+
const DEFAULT_DROPDOWN_DEFINITIONS = [ {
|
|
151
|
+
name: 'imageStyle:wrapText',
|
|
152
|
+
title: 'Wrap text',
|
|
153
|
+
defaultItem: 'imageStyle:alignLeft',
|
|
154
|
+
items: [ 'imageStyle:alignLeft', 'imageStyle:alignRight' ]
|
|
155
|
+
}, {
|
|
156
|
+
name: 'imageStyle:breakText',
|
|
157
|
+
title: 'Break text',
|
|
158
|
+
defaultItem: 'imageStyle:block',
|
|
159
|
+
items: [ 'imageStyle:alignBlockLeft', 'imageStyle:block', 'imageStyle:alignBlockRight' ]
|
|
160
|
+
} ];
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns a list of the normalized and validated image style options.
|
|
164
|
+
*
|
|
165
|
+
* @protected
|
|
166
|
+
* @param {Object} config
|
|
167
|
+
* @param {Boolean} config.isInlinePluginLoaded
|
|
168
|
+
* Determines whether the {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} plugin has been loaded.
|
|
169
|
+
* @param {Boolean} config.isBlockPluginLoaded
|
|
170
|
+
* Determines whether the {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} plugin has been loaded.
|
|
171
|
+
* @param {module:image/imagestyle~ImageStyleConfig} config.configuredStyles
|
|
172
|
+
* The image styles configuration provided in the image styles {@link module:image/image~ImageConfig#styles configuration}
|
|
173
|
+
* as a default or custom value.
|
|
174
|
+
* @returns {module:image/imagestyle~ImageStyleConfig}
|
|
175
|
+
* * Each of options contains a complete icon markup.
|
|
176
|
+
* * The image style options not supported by any of the loaded plugins are filtered out.
|
|
92
177
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
178
|
+
function normalizeStyles( config ) {
|
|
179
|
+
const configuredStyles = config.configuredStyles.options || [];
|
|
180
|
+
|
|
181
|
+
const styles = configuredStyles
|
|
182
|
+
.map( arrangement => normalizeDefinition( arrangement ) )
|
|
183
|
+
.filter( arrangement => isValidOption( arrangement, config ) );
|
|
184
|
+
|
|
185
|
+
return styles;
|
|
95
186
|
}
|
|
96
187
|
|
|
97
|
-
|
|
98
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Returns the default image styles configuration depending on the loaded image editing plugins.
|
|
190
|
+
* @protected
|
|
191
|
+
*
|
|
192
|
+
* @param {Boolean} isInlinePluginLoaded
|
|
193
|
+
* Determines whether the {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} plugin has been loaded.
|
|
194
|
+
*
|
|
195
|
+
* @param {Boolean} isBlockPluginLoaded
|
|
196
|
+
* Determines whether the {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} plugin has been loaded.
|
|
197
|
+
*
|
|
198
|
+
* @returns {Object<String,Array>}
|
|
199
|
+
* It returns an object with the lists of the image style options and groups defined as strings related to the
|
|
200
|
+
* {@link module:image/imagestyle/utils~DEFAULT_OPTIONS default options}
|
|
201
|
+
*/
|
|
202
|
+
function getDefaultStylesConfiguration( isBlockPluginLoaded, isInlinePluginLoaded ) {
|
|
203
|
+
if ( isBlockPluginLoaded && isInlinePluginLoaded ) {
|
|
204
|
+
return {
|
|
205
|
+
options: [
|
|
206
|
+
'inline', 'alignLeft', 'alignRight',
|
|
207
|
+
'alignCenter', 'alignBlockLeft', 'alignBlockRight',
|
|
208
|
+
'block', 'side'
|
|
209
|
+
]
|
|
210
|
+
};
|
|
211
|
+
} else if ( isBlockPluginLoaded ) {
|
|
212
|
+
return {
|
|
213
|
+
options: [ 'block', 'side' ]
|
|
214
|
+
};
|
|
215
|
+
} else if ( isInlinePluginLoaded ) {
|
|
216
|
+
return {
|
|
217
|
+
options: [ 'inline', 'alignLeft', 'alignRight' ]
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return {};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Returns a list of the available predefined drop-downs' definitions depending on the loaded image editing plugins.
|
|
226
|
+
* @protected
|
|
227
|
+
*
|
|
228
|
+
* @param {module:core/plugincollection~PluginCollection} pluginCollection
|
|
229
|
+
* @returns {Array.<module:image/imagestyle/imagestyleui~ImageStyleDropdownDefinition>}
|
|
230
|
+
*/
|
|
231
|
+
function getDefaultDropdownDefinitions( pluginCollection ) {
|
|
232
|
+
if ( pluginCollection.has( 'ImageBlockEditing' ) && pluginCollection.has( 'ImageInlineEditing' ) ) {
|
|
233
|
+
return [ ...DEFAULT_DROPDOWN_DEFINITIONS ];
|
|
234
|
+
} else {
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Normalizes an image style option or group provided in the {@link module:image/image~ImageConfig#styles}
|
|
240
|
+
// and returns it in a {@link module:image/imagestyle~ImageStyleOptionDefinition}/
|
|
99
241
|
//
|
|
100
|
-
// @param {Object}
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if ( typeof
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// Clone the style to avoid overriding defaults.
|
|
110
|
-
style = Object.assign( {}, defaultStyles[ styleName ] );
|
|
242
|
+
// @param {Object|String} definition
|
|
243
|
+
//
|
|
244
|
+
// @returns {module:image/imagestyle~ImageStyleOptionDefinition}}
|
|
245
|
+
function normalizeDefinition( definition ) {
|
|
246
|
+
if ( typeof definition === 'string' ) {
|
|
247
|
+
// Just the name of the style has been passed, but none of the defaults.
|
|
248
|
+
if ( !DEFAULT_OPTIONS[ definition ] ) {
|
|
249
|
+
// Normalize the style anyway to prevent errors.
|
|
250
|
+
definition = { name: definition };
|
|
111
251
|
}
|
|
112
|
-
//
|
|
252
|
+
// Just the name of the style has been passed and it's one of the defaults, just use it.
|
|
253
|
+
// Clone the style to avoid overriding defaults.
|
|
113
254
|
else {
|
|
255
|
+
definition = { ...DEFAULT_OPTIONS[ definition ] };
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
// If an object style has been passed and if the name matches one of the defaults,
|
|
259
|
+
// extend it with defaults – the user wants to customize a default style.
|
|
260
|
+
// Note: Don't override the user–defined style object, clone it instead.
|
|
261
|
+
definition = extendStyle( DEFAULT_OPTIONS[ definition.name ], definition );
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// If an icon is defined as a string and correspond with a name
|
|
265
|
+
// in default icons, use the default icon provided by the plugin.
|
|
266
|
+
if ( typeof definition.icon === 'string' ) {
|
|
267
|
+
definition.icon = DEFAULT_ICONS[ definition.icon ] || definition.icon;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return definition;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Checks if the image style option is valid:
|
|
274
|
+
// * if it has the modelElements fields defined and filled,
|
|
275
|
+
// * if the defined modelElements are supported by any of the loaded image editing plugins.
|
|
276
|
+
// It also displays a console warning these conditions are not met.
|
|
277
|
+
//
|
|
278
|
+
// @param {module:image/imagestyle~ImageStyleOptionDefinition} image style option
|
|
279
|
+
// @param {Object.<String,Boolean>} { isBlockPluginLoaded, isInlinePluginLoaded }
|
|
280
|
+
//
|
|
281
|
+
// @returns Boolean
|
|
282
|
+
function isValidOption( option, { isBlockPluginLoaded, isInlinePluginLoaded } ) {
|
|
283
|
+
const { modelElements, name } = option;
|
|
284
|
+
|
|
285
|
+
if ( !modelElements || !modelElements.length || !name ) {
|
|
286
|
+
warnInvalidStyle( { style: option } );
|
|
287
|
+
|
|
288
|
+
return false;
|
|
289
|
+
} else {
|
|
290
|
+
const supportedElements = [ isBlockPluginLoaded ? 'imageBlock' : null, isInlinePluginLoaded ? 'imageInline' : null ];
|
|
291
|
+
|
|
292
|
+
// Check if the option is supported by any of the loaded plugins.
|
|
293
|
+
if ( !modelElements.some( elementName => supportedElements.includes( elementName ) ) ) {
|
|
114
294
|
/**
|
|
115
|
-
*
|
|
295
|
+
* In order to work correctly, each image style {@link module:image/imagestyle~ImageStyleOptionDefinition option}
|
|
296
|
+
* requires specific model elements (also: types of images) to be supported by the editor.
|
|
297
|
+
*
|
|
298
|
+
* Model element names to which the image style option can be applied are defined in the
|
|
299
|
+
* {@link module:image/imagestyle~ImageStyleOptionDefinition#modelElements} property of the style option
|
|
300
|
+
* definition.
|
|
116
301
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
302
|
+
* Explore the warning in the console to find out precisely which option is not supported and which editor plugins
|
|
303
|
+
* are missing. Make sure these plugins are loaded in your editor to get this image style option working.
|
|
304
|
+
*
|
|
305
|
+
* @error image-style-missing-dependency
|
|
306
|
+
* @param {String} [option] The name of the unsupported option.
|
|
307
|
+
* @param {String} [missingPlugins] The names of the plugins one of which has to be loaded for the particular option.
|
|
119
308
|
*/
|
|
120
|
-
logWarning( 'image-style-
|
|
309
|
+
logWarning( 'image-style-missing-dependency', {
|
|
310
|
+
style: option,
|
|
311
|
+
missingPlugins: modelElements.map( name => name === 'imageBlock' ? 'ImageBlockEditing' : 'ImageInlineEditing' )
|
|
312
|
+
} );
|
|
121
313
|
|
|
122
|
-
|
|
123
|
-
style = {
|
|
124
|
-
name: styleName
|
|
125
|
-
};
|
|
314
|
+
return false;
|
|
126
315
|
}
|
|
127
316
|
}
|
|
128
|
-
// If an object style has been passed and if the name matches one of the defaults,
|
|
129
|
-
// extend it with defaults – the user wants to customize a default style.
|
|
130
|
-
// Note: Don't override the user–defined style object, clone it instead.
|
|
131
|
-
else if ( defaultStyles[ style.name ] ) {
|
|
132
|
-
const defaultStyle = defaultStyles[ style.name ];
|
|
133
|
-
const extendedStyle = Object.assign( {}, style );
|
|
134
|
-
|
|
135
|
-
for ( const prop in defaultStyle ) {
|
|
136
|
-
if ( !Object.prototype.hasOwnProperty.call( style, prop ) ) {
|
|
137
|
-
extendedStyle[ prop ] = defaultStyle[ prop ];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
317
|
|
|
141
|
-
|
|
142
|
-
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
143
320
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
321
|
+
// Extends the default style with a style provided by the developer.
|
|
322
|
+
// Note: Don't override the custom–defined style object, clone it instead.
|
|
323
|
+
//
|
|
324
|
+
// @param {module:image/imagestyle~ImageStyleOptionDefinition} source
|
|
325
|
+
// @param {Object} style
|
|
326
|
+
//
|
|
327
|
+
// @returns {module:image/imagestyle~ImageStyleOptionDefinition}
|
|
328
|
+
function extendStyle( source, style ) {
|
|
329
|
+
const extendedStyle = { ...style };
|
|
330
|
+
|
|
331
|
+
for ( const prop in source ) {
|
|
332
|
+
if ( !Object.prototype.hasOwnProperty.call( style, prop ) ) {
|
|
333
|
+
extendedStyle[ prop ] = source[ prop ];
|
|
334
|
+
}
|
|
148
335
|
}
|
|
149
336
|
|
|
150
|
-
return
|
|
337
|
+
return extendedStyle;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Displays a console warning with the 'image-style-configuration-definition-invalid' error.
|
|
341
|
+
// @param {Object} info
|
|
342
|
+
function warnInvalidStyle( info ) {
|
|
343
|
+
/**
|
|
344
|
+
* The image style definition provided in the configuration is invalid.
|
|
345
|
+
*
|
|
346
|
+
* Please make sure the definition implements properly one of the following:
|
|
347
|
+
*
|
|
348
|
+
* * {@link module:image/imagestyle~ImageStyleOptionDefinition image style option definition},
|
|
349
|
+
* * {@link module:image/imagestyle/imagestyleui~ImageStyleDropdownDefinition image style dropdown definition}
|
|
350
|
+
*
|
|
351
|
+
* @error image-style-configuration-definition-invalid
|
|
352
|
+
* @param {String} [dropdown] The name of the invalid drop-down
|
|
353
|
+
* @param {String} [style] The name of the invalid image style option
|
|
354
|
+
*/
|
|
355
|
+
logWarning( 'image-style-configuration-definition-invalid', info );
|
|
151
356
|
}
|
|
357
|
+
|
|
358
|
+
export default {
|
|
359
|
+
normalizeStyles,
|
|
360
|
+
getDefaultStylesConfiguration,
|
|
361
|
+
getDefaultDropdownDefinitions,
|
|
362
|
+
warnInvalidStyle,
|
|
363
|
+
DEFAULT_OPTIONS,
|
|
364
|
+
DEFAULT_ICONS,
|
|
365
|
+
DEFAULT_DROPDOWN_DEFINITIONS
|
|
366
|
+
};
|