@ckeditor/ckeditor5-image 39.0.1 → 40.0.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/CHANGELOG.md +1 -1
- package/LICENSE.md +1 -1
- package/README.md +3 -3
- package/build/image.js +1 -1
- package/build/image.js.map +1 -0
- package/build/translations/pt-br.js +1 -1
- package/ckeditor5-metadata.json +12 -0
- package/lang/translations/ar.po +1 -0
- package/lang/translations/ast.po +1 -0
- package/lang/translations/az.po +1 -0
- package/lang/translations/bg.po +1 -0
- package/lang/translations/bn.po +1 -0
- package/lang/translations/bs.po +1 -0
- package/lang/translations/ca.po +1 -0
- package/lang/translations/cs.po +1 -0
- package/lang/translations/da.po +1 -0
- package/lang/translations/de-ch.po +1 -0
- package/lang/translations/de.po +1 -0
- package/lang/translations/el.po +1 -0
- package/lang/translations/en-au.po +1 -0
- package/lang/translations/en-gb.po +1 -0
- package/lang/translations/en.po +1 -0
- package/lang/translations/eo.po +1 -0
- package/lang/translations/es.po +1 -0
- package/lang/translations/et.po +1 -0
- package/lang/translations/eu.po +1 -0
- package/lang/translations/fa.po +1 -0
- package/lang/translations/fi.po +1 -0
- package/lang/translations/fr.po +1 -0
- package/lang/translations/gl.po +1 -0
- package/lang/translations/he.po +1 -0
- package/lang/translations/hi.po +1 -0
- package/lang/translations/hr.po +1 -0
- package/lang/translations/hu.po +1 -0
- package/lang/translations/id.po +1 -0
- package/lang/translations/it.po +1 -0
- package/lang/translations/ja.po +1 -0
- package/lang/translations/jv.po +1 -0
- package/lang/translations/km.po +1 -0
- package/lang/translations/kn.po +1 -0
- package/lang/translations/ko.po +1 -0
- package/lang/translations/ku.po +1 -0
- package/lang/translations/lt.po +1 -0
- package/lang/translations/lv.po +1 -0
- package/lang/translations/ms.po +1 -0
- package/lang/translations/nb.po +1 -0
- package/lang/translations/ne.po +1 -0
- package/lang/translations/nl.po +1 -0
- package/lang/translations/no.po +1 -0
- package/lang/translations/pl.po +1 -0
- package/lang/translations/pt-br.po +2 -1
- package/lang/translations/pt.po +1 -0
- package/lang/translations/ro.po +1 -0
- package/lang/translations/ru.po +1 -0
- package/lang/translations/si.po +1 -0
- package/lang/translations/sk.po +1 -0
- package/lang/translations/sq.po +1 -0
- package/lang/translations/sr-latn.po +1 -0
- package/lang/translations/sr.po +1 -0
- package/lang/translations/sv.po +1 -0
- package/lang/translations/th.po +1 -0
- package/lang/translations/tk.po +1 -0
- package/lang/translations/tr.po +1 -0
- package/lang/translations/tt.po +1 -0
- package/lang/translations/ug.po +1 -0
- package/lang/translations/uk.po +1 -0
- package/lang/translations/ur.po +1 -0
- package/lang/translations/uz.po +1 -0
- package/lang/translations/vi.po +1 -0
- package/lang/translations/zh-cn.po +1 -0
- package/lang/translations/zh.po +1 -0
- package/package.json +3 -7
- package/src/augmentation.d.ts +56 -55
- package/src/augmentation.js +5 -5
- package/src/autoimage.d.ts +52 -52
- package/src/autoimage.js +132 -132
- package/src/image/converters.d.ts +66 -66
- package/src/image/converters.js +232 -242
- package/src/image/imageblockediting.d.ts +58 -55
- package/src/image/imageblockediting.js +152 -136
- package/src/image/imageediting.d.ts +30 -30
- package/src/image/imageediting.js +63 -74
- package/src/image/imageinlineediting.d.ts +59 -56
- package/src/image/imageinlineediting.js +176 -160
- package/src/image/imageloadobserver.d.ts +48 -48
- package/src/image/imageloadobserver.js +52 -52
- package/src/image/imagetypecommand.d.ts +44 -40
- package/src/image/imagetypecommand.js +80 -77
- package/src/image/insertimagecommand.d.ts +66 -66
- package/src/image/insertimagecommand.js +120 -120
- package/src/image/replaceimagesourcecommand.d.ts +34 -34
- package/src/image/replaceimagesourcecommand.js +44 -44
- package/src/image/ui/utils.d.ts +25 -25
- package/src/image/ui/utils.js +44 -44
- package/src/image/utils.d.ts +64 -52
- package/src/image/utils.js +121 -100
- package/src/image.d.ts +34 -34
- package/src/image.js +38 -38
- package/src/imageblock.d.ts +33 -33
- package/src/imageblock.js +37 -37
- package/src/imagecaption/imagecaptionediting.d.ts +89 -89
- package/src/imagecaption/imagecaptionediting.js +225 -225
- package/src/imagecaption/imagecaptionui.d.ts +26 -26
- package/src/imagecaption/imagecaptionui.js +61 -61
- package/src/imagecaption/imagecaptionutils.d.ts +38 -38
- package/src/imagecaption/imagecaptionutils.js +62 -62
- package/src/imagecaption/toggleimagecaptioncommand.d.ts +66 -66
- package/src/imagecaption/toggleimagecaptioncommand.js +138 -138
- package/src/imagecaption.d.ts +26 -26
- package/src/imagecaption.js +30 -30
- package/src/imageconfig.d.ts +713 -713
- package/src/imageconfig.js +5 -5
- package/src/imageinline.d.ts +33 -33
- package/src/imageinline.js +37 -37
- package/src/imageinsert/imageinsertui.d.ts +44 -44
- package/src/imageinsert/imageinsertui.js +141 -141
- package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -61
- package/src/imageinsert/ui/imageinsertformrowview.js +54 -54
- package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -106
- package/src/imageinsert/ui/imageinsertpanelview.js +161 -161
- package/src/imageinsert/utils.d.ts +25 -25
- package/src/imageinsert/utils.js +58 -58
- package/src/imageinsert.d.ts +33 -33
- package/src/imageinsert.js +37 -37
- package/src/imageinsertviaurl.d.ts +30 -30
- package/src/imageinsertviaurl.js +34 -34
- package/src/imageresize/imageresizebuttons.d.ts +67 -67
- package/src/imageresize/imageresizebuttons.js +217 -217
- package/src/imageresize/imageresizeediting.d.ts +37 -37
- package/src/imageresize/imageresizeediting.js +165 -114
- package/src/imageresize/imageresizehandles.d.ts +31 -30
- package/src/imageresize/imageresizehandles.js +114 -107
- package/src/imageresize/resizeimagecommand.d.ts +42 -42
- package/src/imageresize/resizeimagecommand.js +63 -61
- package/src/imageresize.d.ts +27 -27
- package/src/imageresize.js +31 -31
- package/src/imagesizeattributes.d.ts +34 -0
- package/src/imagesizeattributes.js +143 -0
- package/src/imagestyle/converters.d.ts +24 -24
- package/src/imagestyle/converters.js +79 -79
- package/src/imagestyle/imagestylecommand.d.ts +68 -65
- package/src/imagestyle/imagestylecommand.js +107 -101
- package/src/imagestyle/imagestyleediting.d.ts +50 -50
- package/src/imagestyle/imagestyleediting.js +108 -108
- package/src/imagestyle/imagestyleui.d.ts +56 -56
- package/src/imagestyle/imagestyleui.js +192 -192
- package/src/imagestyle/utils.d.ts +101 -101
- package/src/imagestyle/utils.js +329 -329
- package/src/imagestyle.d.ts +32 -32
- package/src/imagestyle.js +36 -36
- package/src/imagetextalternative/imagetextalternativecommand.d.ts +34 -34
- package/src/imagetextalternative/imagetextalternativecommand.js +44 -44
- package/src/imagetextalternative/imagetextalternativeediting.d.ts +28 -28
- package/src/imagetextalternative/imagetextalternativeediting.js +35 -35
- package/src/imagetextalternative/imagetextalternativeui.d.ts +68 -68
- package/src/imagetextalternative/imagetextalternativeui.js +173 -173
- package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -72
- package/src/imagetextalternative/ui/textalternativeformview.js +121 -121
- package/src/imagetextalternative.d.ts +29 -29
- package/src/imagetextalternative.js +33 -33
- package/src/imagetoolbar.d.ts +35 -35
- package/src/imagetoolbar.js +57 -57
- package/src/imageupload/imageuploadediting.d.ts +111 -111
- package/src/imageupload/imageuploadediting.js +337 -335
- package/src/imageupload/imageuploadprogress.d.ts +42 -42
- package/src/imageupload/imageuploadprogress.js +211 -211
- package/src/imageupload/imageuploadui.d.ts +23 -23
- package/src/imageupload/imageuploadui.js +57 -57
- package/src/imageupload/uploadimagecommand.d.ts +60 -60
- package/src/imageupload/uploadimagecommand.js +100 -100
- package/src/imageupload/utils.d.ts +33 -33
- package/src/imageupload/utils.js +112 -112
- package/src/imageupload.d.ts +32 -32
- package/src/imageupload.js +36 -36
- package/src/imageutils.d.ts +125 -102
- package/src/imageutils.js +306 -248
- package/src/index.d.ts +48 -47
- package/src/index.js +39 -38
- package/src/pictureediting.d.ts +88 -88
- package/src/pictureediting.js +130 -130
- package/theme/image.css +38 -11
- package/theme/imageresize.css +5 -0
|
@@ -1,192 +1,192 @@
|
|
|
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 image/imagestyle/imagestyleui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { ButtonView, createDropdown, addToolbarToDropdown, SplitButtonView } from 'ckeditor5/src/ui';
|
|
10
|
-
import { isObject, identity } from 'lodash-es';
|
|
11
|
-
import ImageStyleEditing from './imagestyleediting';
|
|
12
|
-
import utils from './utils';
|
|
13
|
-
import '../../theme/imagestyle.css';
|
|
14
|
-
/**
|
|
15
|
-
* The image style UI plugin.
|
|
16
|
-
*
|
|
17
|
-
* It registers buttons corresponding to the {@link module:image/imageconfig~ImageConfig#styles} configuration.
|
|
18
|
-
* It also registers the {@link module:image/imagestyle/utils#DEFAULT_DROPDOWN_DEFINITIONS default drop-downs} and the
|
|
19
|
-
* custom drop-downs defined by the developer in the {@link module:image/imageconfig~ImageConfig#toolbar} configuration.
|
|
20
|
-
*/
|
|
21
|
-
export default class ImageStyleUI extends Plugin {
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
static get requires() {
|
|
26
|
-
return [ImageStyleEditing];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @inheritDoc
|
|
30
|
-
*/
|
|
31
|
-
static get pluginName() {
|
|
32
|
-
return 'ImageStyleUI';
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Returns the default localized style titles provided by the plugin.
|
|
36
|
-
*
|
|
37
|
-
* The following localized titles corresponding with
|
|
38
|
-
* {@link module:image/imagestyle/utils#DEFAULT_OPTIONS} are available:
|
|
39
|
-
*
|
|
40
|
-
* * `'Wrap text'`,
|
|
41
|
-
* * `'Break text'`,
|
|
42
|
-
* * `'In line'`,
|
|
43
|
-
* * `'Full size image'`,
|
|
44
|
-
* * `'Side image'`,
|
|
45
|
-
* * `'Left aligned image'`,
|
|
46
|
-
* * `'Centered image'`,
|
|
47
|
-
* * `'Right aligned image'`
|
|
48
|
-
*/
|
|
49
|
-
get localizedDefaultStylesTitles() {
|
|
50
|
-
const t = this.editor.t;
|
|
51
|
-
return {
|
|
52
|
-
'Wrap text': t('Wrap text'),
|
|
53
|
-
'Break text': t('Break text'),
|
|
54
|
-
'In line': t('In line'),
|
|
55
|
-
'Full size image': t('Full size image'),
|
|
56
|
-
'Side image': t('Side image'),
|
|
57
|
-
'Left aligned image': t('Left aligned image'),
|
|
58
|
-
'Centered image': t('Centered image'),
|
|
59
|
-
'Right aligned image': t('Right aligned image')
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* @inheritDoc
|
|
64
|
-
*/
|
|
65
|
-
init() {
|
|
66
|
-
const plugins = this.editor.plugins;
|
|
67
|
-
const toolbarConfig = this.editor.config.get('image.toolbar') || [];
|
|
68
|
-
const imageStyleEditing = plugins.get('ImageStyleEditing');
|
|
69
|
-
const definedStyles = translateStyles(imageStyleEditing.normalizedStyles, this.localizedDefaultStylesTitles);
|
|
70
|
-
for (const styleConfig of definedStyles) {
|
|
71
|
-
this._createButton(styleConfig);
|
|
72
|
-
}
|
|
73
|
-
const definedDropdowns = translateStyles([
|
|
74
|
-
...toolbarConfig.filter(isObject),
|
|
75
|
-
...utils.getDefaultDropdownDefinitions(plugins)
|
|
76
|
-
], this.localizedDefaultStylesTitles);
|
|
77
|
-
for (const dropdownConfig of definedDropdowns) {
|
|
78
|
-
this._createDropdown(dropdownConfig, definedStyles);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Creates a dropdown and stores it in the editor {@link module:ui/componentfactory~ComponentFactory}.
|
|
83
|
-
*/
|
|
84
|
-
_createDropdown(dropdownConfig, definedStyles) {
|
|
85
|
-
const factory = this.editor.ui.componentFactory;
|
|
86
|
-
factory.add(dropdownConfig.name, locale => {
|
|
87
|
-
let defaultButton;
|
|
88
|
-
const { defaultItem, items, title } = dropdownConfig;
|
|
89
|
-
const buttonViews = items
|
|
90
|
-
.filter(itemName => definedStyles.find(({ name }) => getUIComponentName(name) === itemName))
|
|
91
|
-
.map(buttonName => {
|
|
92
|
-
const button = factory.create(buttonName);
|
|
93
|
-
if (buttonName === defaultItem) {
|
|
94
|
-
defaultButton = button;
|
|
95
|
-
}
|
|
96
|
-
return button;
|
|
97
|
-
});
|
|
98
|
-
if (items.length !== buttonViews.length) {
|
|
99
|
-
utils.warnInvalidStyle({ dropdown: dropdownConfig });
|
|
100
|
-
}
|
|
101
|
-
const dropdownView = createDropdown(locale, SplitButtonView);
|
|
102
|
-
const splitButtonView = dropdownView.buttonView;
|
|
103
|
-
const splitButtonViewArrow = splitButtonView.arrowView;
|
|
104
|
-
addToolbarToDropdown(dropdownView, buttonViews, { enableActiveItemFocusOnDropdownOpen: true });
|
|
105
|
-
splitButtonView.set({
|
|
106
|
-
label: getDropdownButtonTitle(title, defaultButton.label),
|
|
107
|
-
class: null,
|
|
108
|
-
tooltip: true
|
|
109
|
-
});
|
|
110
|
-
splitButtonViewArrow.unbind('label');
|
|
111
|
-
splitButtonViewArrow.set({
|
|
112
|
-
label: title
|
|
113
|
-
});
|
|
114
|
-
splitButtonView.bind('icon').toMany(buttonViews, 'isOn', (...areOn) => {
|
|
115
|
-
const index = areOn.findIndex(identity);
|
|
116
|
-
return (index < 0) ? defaultButton.icon : buttonViews[index].icon;
|
|
117
|
-
});
|
|
118
|
-
splitButtonView.bind('label').toMany(buttonViews, 'isOn', (...areOn) => {
|
|
119
|
-
const index = areOn.findIndex(identity);
|
|
120
|
-
return getDropdownButtonTitle(title, (index < 0) ? defaultButton.label : buttonViews[index].label);
|
|
121
|
-
});
|
|
122
|
-
splitButtonView.bind('isOn').toMany(buttonViews, 'isOn', (...areOn) => areOn.some(identity));
|
|
123
|
-
splitButtonView.bind('class')
|
|
124
|
-
.toMany(buttonViews, 'isOn', (...areOn) => areOn.some(identity) ? 'ck-splitbutton_flatten' : undefined);
|
|
125
|
-
splitButtonView.on('execute', () => {
|
|
126
|
-
if (!buttonViews.some(({ isOn }) => isOn)) {
|
|
127
|
-
defaultButton.fire('execute');
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
dropdownView.isOpen = !dropdownView.isOpen;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
dropdownView.bind('isEnabled')
|
|
134
|
-
.toMany(buttonViews, 'isEnabled', (...areEnabled) => areEnabled.some(identity));
|
|
135
|
-
// Focus the editable after executing the command.
|
|
136
|
-
// Overrides a default behaviour where the focus is moved to the dropdown button (#12125).
|
|
137
|
-
this.listenTo(dropdownView, 'execute', () => {
|
|
138
|
-
this.editor.editing.view.focus();
|
|
139
|
-
});
|
|
140
|
-
return dropdownView;
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Creates a button and stores it in the editor {@link module:ui/componentfactory~ComponentFactory}.
|
|
145
|
-
*/
|
|
146
|
-
_createButton(buttonConfig) {
|
|
147
|
-
const buttonName = buttonConfig.name;
|
|
148
|
-
this.editor.ui.componentFactory.add(getUIComponentName(buttonName), locale => {
|
|
149
|
-
const command = this.editor.commands.get('imageStyle');
|
|
150
|
-
const view = new ButtonView(locale);
|
|
151
|
-
view.set({
|
|
152
|
-
label: buttonConfig.title,
|
|
153
|
-
icon: buttonConfig.icon,
|
|
154
|
-
tooltip: true,
|
|
155
|
-
isToggleable: true
|
|
156
|
-
});
|
|
157
|
-
view.bind('isEnabled').to(command, 'isEnabled');
|
|
158
|
-
view.bind('isOn').to(command, 'value', value => value === buttonName);
|
|
159
|
-
view.on('execute', this._executeCommand.bind(this, buttonName));
|
|
160
|
-
return view;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
_executeCommand(name) {
|
|
164
|
-
this.editor.execute('imageStyle', { value: name });
|
|
165
|
-
this.editor.editing.view.focus();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Returns the translated `title` from the passed styles array.
|
|
170
|
-
*/
|
|
171
|
-
function translateStyles(styles, titles) {
|
|
172
|
-
for (const style of styles) {
|
|
173
|
-
// Localize the titles of the styles, if a title corresponds with
|
|
174
|
-
// a localized default provided by the plugin.
|
|
175
|
-
if (titles[style.title]) {
|
|
176
|
-
style.title = titles[style.title];
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return styles;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Returns the image style component name with the "imageStyle:" prefix.
|
|
183
|
-
*/
|
|
184
|
-
function getUIComponentName(name) {
|
|
185
|
-
return `imageStyle:${name}`;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Returns title for the splitbutton containing the dropdown title and default action item title.
|
|
189
|
-
*/
|
|
190
|
-
function getDropdownButtonTitle(dropdownTitle, buttonTitle) {
|
|
191
|
-
return (dropdownTitle ? dropdownTitle + ': ' : '') + buttonTitle;
|
|
192
|
-
}
|
|
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 image/imagestyle/imagestyleui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { ButtonView, createDropdown, addToolbarToDropdown, SplitButtonView } from 'ckeditor5/src/ui';
|
|
10
|
+
import { isObject, identity } from 'lodash-es';
|
|
11
|
+
import ImageStyleEditing from './imagestyleediting';
|
|
12
|
+
import utils from './utils';
|
|
13
|
+
import '../../theme/imagestyle.css';
|
|
14
|
+
/**
|
|
15
|
+
* The image style UI plugin.
|
|
16
|
+
*
|
|
17
|
+
* It registers buttons corresponding to the {@link module:image/imageconfig~ImageConfig#styles} configuration.
|
|
18
|
+
* It also registers the {@link module:image/imagestyle/utils#DEFAULT_DROPDOWN_DEFINITIONS default drop-downs} and the
|
|
19
|
+
* custom drop-downs defined by the developer in the {@link module:image/imageconfig~ImageConfig#toolbar} configuration.
|
|
20
|
+
*/
|
|
21
|
+
export default class ImageStyleUI extends Plugin {
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
static get requires() {
|
|
26
|
+
return [ImageStyleEditing];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
static get pluginName() {
|
|
32
|
+
return 'ImageStyleUI';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns the default localized style titles provided by the plugin.
|
|
36
|
+
*
|
|
37
|
+
* The following localized titles corresponding with
|
|
38
|
+
* {@link module:image/imagestyle/utils#DEFAULT_OPTIONS} are available:
|
|
39
|
+
*
|
|
40
|
+
* * `'Wrap text'`,
|
|
41
|
+
* * `'Break text'`,
|
|
42
|
+
* * `'In line'`,
|
|
43
|
+
* * `'Full size image'`,
|
|
44
|
+
* * `'Side image'`,
|
|
45
|
+
* * `'Left aligned image'`,
|
|
46
|
+
* * `'Centered image'`,
|
|
47
|
+
* * `'Right aligned image'`
|
|
48
|
+
*/
|
|
49
|
+
get localizedDefaultStylesTitles() {
|
|
50
|
+
const t = this.editor.t;
|
|
51
|
+
return {
|
|
52
|
+
'Wrap text': t('Wrap text'),
|
|
53
|
+
'Break text': t('Break text'),
|
|
54
|
+
'In line': t('In line'),
|
|
55
|
+
'Full size image': t('Full size image'),
|
|
56
|
+
'Side image': t('Side image'),
|
|
57
|
+
'Left aligned image': t('Left aligned image'),
|
|
58
|
+
'Centered image': t('Centered image'),
|
|
59
|
+
'Right aligned image': t('Right aligned image')
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @inheritDoc
|
|
64
|
+
*/
|
|
65
|
+
init() {
|
|
66
|
+
const plugins = this.editor.plugins;
|
|
67
|
+
const toolbarConfig = this.editor.config.get('image.toolbar') || [];
|
|
68
|
+
const imageStyleEditing = plugins.get('ImageStyleEditing');
|
|
69
|
+
const definedStyles = translateStyles(imageStyleEditing.normalizedStyles, this.localizedDefaultStylesTitles);
|
|
70
|
+
for (const styleConfig of definedStyles) {
|
|
71
|
+
this._createButton(styleConfig);
|
|
72
|
+
}
|
|
73
|
+
const definedDropdowns = translateStyles([
|
|
74
|
+
...toolbarConfig.filter(isObject),
|
|
75
|
+
...utils.getDefaultDropdownDefinitions(plugins)
|
|
76
|
+
], this.localizedDefaultStylesTitles);
|
|
77
|
+
for (const dropdownConfig of definedDropdowns) {
|
|
78
|
+
this._createDropdown(dropdownConfig, definedStyles);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Creates a dropdown and stores it in the editor {@link module:ui/componentfactory~ComponentFactory}.
|
|
83
|
+
*/
|
|
84
|
+
_createDropdown(dropdownConfig, definedStyles) {
|
|
85
|
+
const factory = this.editor.ui.componentFactory;
|
|
86
|
+
factory.add(dropdownConfig.name, locale => {
|
|
87
|
+
let defaultButton;
|
|
88
|
+
const { defaultItem, items, title } = dropdownConfig;
|
|
89
|
+
const buttonViews = items
|
|
90
|
+
.filter(itemName => definedStyles.find(({ name }) => getUIComponentName(name) === itemName))
|
|
91
|
+
.map(buttonName => {
|
|
92
|
+
const button = factory.create(buttonName);
|
|
93
|
+
if (buttonName === defaultItem) {
|
|
94
|
+
defaultButton = button;
|
|
95
|
+
}
|
|
96
|
+
return button;
|
|
97
|
+
});
|
|
98
|
+
if (items.length !== buttonViews.length) {
|
|
99
|
+
utils.warnInvalidStyle({ dropdown: dropdownConfig });
|
|
100
|
+
}
|
|
101
|
+
const dropdownView = createDropdown(locale, SplitButtonView);
|
|
102
|
+
const splitButtonView = dropdownView.buttonView;
|
|
103
|
+
const splitButtonViewArrow = splitButtonView.arrowView;
|
|
104
|
+
addToolbarToDropdown(dropdownView, buttonViews, { enableActiveItemFocusOnDropdownOpen: true });
|
|
105
|
+
splitButtonView.set({
|
|
106
|
+
label: getDropdownButtonTitle(title, defaultButton.label),
|
|
107
|
+
class: null,
|
|
108
|
+
tooltip: true
|
|
109
|
+
});
|
|
110
|
+
splitButtonViewArrow.unbind('label');
|
|
111
|
+
splitButtonViewArrow.set({
|
|
112
|
+
label: title
|
|
113
|
+
});
|
|
114
|
+
splitButtonView.bind('icon').toMany(buttonViews, 'isOn', (...areOn) => {
|
|
115
|
+
const index = areOn.findIndex(identity);
|
|
116
|
+
return (index < 0) ? defaultButton.icon : buttonViews[index].icon;
|
|
117
|
+
});
|
|
118
|
+
splitButtonView.bind('label').toMany(buttonViews, 'isOn', (...areOn) => {
|
|
119
|
+
const index = areOn.findIndex(identity);
|
|
120
|
+
return getDropdownButtonTitle(title, (index < 0) ? defaultButton.label : buttonViews[index].label);
|
|
121
|
+
});
|
|
122
|
+
splitButtonView.bind('isOn').toMany(buttonViews, 'isOn', (...areOn) => areOn.some(identity));
|
|
123
|
+
splitButtonView.bind('class')
|
|
124
|
+
.toMany(buttonViews, 'isOn', (...areOn) => areOn.some(identity) ? 'ck-splitbutton_flatten' : undefined);
|
|
125
|
+
splitButtonView.on('execute', () => {
|
|
126
|
+
if (!buttonViews.some(({ isOn }) => isOn)) {
|
|
127
|
+
defaultButton.fire('execute');
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
dropdownView.isOpen = !dropdownView.isOpen;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
dropdownView.bind('isEnabled')
|
|
134
|
+
.toMany(buttonViews, 'isEnabled', (...areEnabled) => areEnabled.some(identity));
|
|
135
|
+
// Focus the editable after executing the command.
|
|
136
|
+
// Overrides a default behaviour where the focus is moved to the dropdown button (#12125).
|
|
137
|
+
this.listenTo(dropdownView, 'execute', () => {
|
|
138
|
+
this.editor.editing.view.focus();
|
|
139
|
+
});
|
|
140
|
+
return dropdownView;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Creates a button and stores it in the editor {@link module:ui/componentfactory~ComponentFactory}.
|
|
145
|
+
*/
|
|
146
|
+
_createButton(buttonConfig) {
|
|
147
|
+
const buttonName = buttonConfig.name;
|
|
148
|
+
this.editor.ui.componentFactory.add(getUIComponentName(buttonName), locale => {
|
|
149
|
+
const command = this.editor.commands.get('imageStyle');
|
|
150
|
+
const view = new ButtonView(locale);
|
|
151
|
+
view.set({
|
|
152
|
+
label: buttonConfig.title,
|
|
153
|
+
icon: buttonConfig.icon,
|
|
154
|
+
tooltip: true,
|
|
155
|
+
isToggleable: true
|
|
156
|
+
});
|
|
157
|
+
view.bind('isEnabled').to(command, 'isEnabled');
|
|
158
|
+
view.bind('isOn').to(command, 'value', value => value === buttonName);
|
|
159
|
+
view.on('execute', this._executeCommand.bind(this, buttonName));
|
|
160
|
+
return view;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
_executeCommand(name) {
|
|
164
|
+
this.editor.execute('imageStyle', { value: name });
|
|
165
|
+
this.editor.editing.view.focus();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Returns the translated `title` from the passed styles array.
|
|
170
|
+
*/
|
|
171
|
+
function translateStyles(styles, titles) {
|
|
172
|
+
for (const style of styles) {
|
|
173
|
+
// Localize the titles of the styles, if a title corresponds with
|
|
174
|
+
// a localized default provided by the plugin.
|
|
175
|
+
if (titles[style.title]) {
|
|
176
|
+
style.title = titles[style.title];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return styles;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Returns the image style component name with the "imageStyle:" prefix.
|
|
183
|
+
*/
|
|
184
|
+
function getUIComponentName(name) {
|
|
185
|
+
return `imageStyle:${name}`;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns title for the splitbutton containing the dropdown title and default action item title.
|
|
189
|
+
*/
|
|
190
|
+
function getDropdownButtonTitle(dropdownTitle, buttonTitle) {
|
|
191
|
+
return (dropdownTitle ? dropdownTitle + ': ' : '') + buttonTitle;
|
|
192
|
+
}
|
|
@@ -1,101 +1,101 @@
|
|
|
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 image/imagestyle/utils
|
|
7
|
-
*/
|
|
8
|
-
import { type Editor, type PluginCollection } from 'ckeditor5/src/core';
|
|
9
|
-
import type { ImageStyleConfig, ImageStyleDropdownDefinition, ImageStyleOptionDefinition } from '../imageconfig';
|
|
10
|
-
/**
|
|
11
|
-
* Default image style options provided by the plugin that can be referred in the {@link module:image/imageconfig~ImageConfig#styles}
|
|
12
|
-
* configuration.
|
|
13
|
-
*
|
|
14
|
-
* There are available 5 styles focused on formatting:
|
|
15
|
-
*
|
|
16
|
-
* * **`'alignLeft'`** aligns the inline or block image to the left and wraps it with the text using the `image-style-align-left` class,
|
|
17
|
-
* * **`'alignRight'`** aligns the inline or block image to the right and wraps it with the text using the `image-style-align-right` class,
|
|
18
|
-
* * **`'alignCenter'`** centers the block image using the `image-style-align-center` class,
|
|
19
|
-
* * **`'alignBlockLeft'`** aligns the block image to the left using the `image-style-block-align-left` class,
|
|
20
|
-
* * **`'alignBlockRight'`** aligns the block image to the right using the `image-style-block-align-right` class,
|
|
21
|
-
*
|
|
22
|
-
* and 3 semantic styles:
|
|
23
|
-
*
|
|
24
|
-
* * **`'inline'`** is an inline image without any CSS class,
|
|
25
|
-
* * **`'block'`** is a block image without any CSS class,
|
|
26
|
-
* * **`'side'`** is a block image styled with the `image-style-side` CSS class.
|
|
27
|
-
*/
|
|
28
|
-
export declare const DEFAULT_OPTIONS: Record<string, ImageStyleOptionDefinition>;
|
|
29
|
-
/**
|
|
30
|
-
* Default image style icons provided by the plugin that can be referred in the {@link module:image/imageconfig~ImageConfig#styles}
|
|
31
|
-
* configuration.
|
|
32
|
-
*
|
|
33
|
-
* See {@link module:image/imageconfig~ImageStyleOptionDefinition#icon} to learn more.
|
|
34
|
-
*
|
|
35
|
-
* There are 7 default icons available: `'full'`, `'left'`, `'inlineLeft'`, `'center'`, `'right'`, `'inlineRight'`, and `'inline'`.
|
|
36
|
-
*/
|
|
37
|
-
export declare const DEFAULT_ICONS: Record<string, string>;
|
|
38
|
-
/**
|
|
39
|
-
* Default drop-downs provided by the plugin that can be referred in the {@link module:image/imageconfig~ImageConfig#toolbar}
|
|
40
|
-
* configuration. The drop-downs are containers for the {@link module:image/imageconfig~ImageStyleConfig#options image style options}.
|
|
41
|
-
*
|
|
42
|
-
* If both of the `ImageEditing` plugins are loaded, there are 2 predefined drop-downs available:
|
|
43
|
-
*
|
|
44
|
-
* * **`'imageStyle:wrapText'`**, which contains the `alignLeft` and `alignRight` options, that is,
|
|
45
|
-
* those that wraps the text around the image,
|
|
46
|
-
* * **`'imageStyle:breakText'`**, which contains the `alignBlockLeft`, `alignCenter` and `alignBlockRight` options, that is,
|
|
47
|
-
* those that breaks the text around the image.
|
|
48
|
-
*/
|
|
49
|
-
export declare const DEFAULT_DROPDOWN_DEFINITIONS: Array<ImageStyleDropdownDefinition>;
|
|
50
|
-
/**
|
|
51
|
-
* Returns a list of the normalized and validated image style options.
|
|
52
|
-
*
|
|
53
|
-
* @param config
|
|
54
|
-
* @param config.isInlinePluginLoaded
|
|
55
|
-
* Determines whether the {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} plugin has been loaded.
|
|
56
|
-
* @param config.isBlockPluginLoaded
|
|
57
|
-
* Determines whether the {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} plugin has been loaded.
|
|
58
|
-
* @param config.configuredStyles
|
|
59
|
-
* The image styles configuration provided in the image styles {@link module:image/imageconfig~ImageConfig#styles configuration}
|
|
60
|
-
* as a default or custom value.
|
|
61
|
-
* @returns
|
|
62
|
-
* * Each of options contains a complete icon markup.
|
|
63
|
-
* * The image style options not supported by any of the loaded plugins are filtered out.
|
|
64
|
-
*/
|
|
65
|
-
declare function normalizeStyles(config: {
|
|
66
|
-
isInlinePluginLoaded: boolean;
|
|
67
|
-
isBlockPluginLoaded: boolean;
|
|
68
|
-
configuredStyles: ImageStyleConfig;
|
|
69
|
-
}): Array<ImageStyleOptionDefinition>;
|
|
70
|
-
/**
|
|
71
|
-
* Returns the default image styles configuration depending on the loaded image editing plugins.
|
|
72
|
-
*
|
|
73
|
-
* @param isInlinePluginLoaded
|
|
74
|
-
* Determines whether the {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} plugin has been loaded.
|
|
75
|
-
*
|
|
76
|
-
* @param isBlockPluginLoaded
|
|
77
|
-
* Determines whether the {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} plugin has been loaded.
|
|
78
|
-
*
|
|
79
|
-
* @returns
|
|
80
|
-
* It returns an object with the lists of the image style options and groups defined as strings related to the
|
|
81
|
-
* {@link module:image/imagestyle/utils#DEFAULT_OPTIONS default options}
|
|
82
|
-
*/
|
|
83
|
-
declare function getDefaultStylesConfiguration(isBlockPluginLoaded: boolean, isInlinePluginLoaded: boolean): ImageStyleConfig;
|
|
84
|
-
/**
|
|
85
|
-
* Returns a list of the available predefined drop-downs' definitions depending on the loaded image editing plugins.
|
|
86
|
-
*/
|
|
87
|
-
declare function getDefaultDropdownDefinitions(pluginCollection: PluginCollection<Editor>): Array<ImageStyleDropdownDefinition>;
|
|
88
|
-
/**
|
|
89
|
-
* Displays a console warning with the 'image-style-configuration-definition-invalid' error.
|
|
90
|
-
*/
|
|
91
|
-
declare function warnInvalidStyle(info: object): void;
|
|
92
|
-
declare const _default: {
|
|
93
|
-
normalizeStyles: typeof normalizeStyles;
|
|
94
|
-
getDefaultStylesConfiguration: typeof getDefaultStylesConfiguration;
|
|
95
|
-
getDefaultDropdownDefinitions: typeof getDefaultDropdownDefinitions;
|
|
96
|
-
warnInvalidStyle: typeof warnInvalidStyle;
|
|
97
|
-
DEFAULT_OPTIONS: Record<string, ImageStyleOptionDefinition>;
|
|
98
|
-
DEFAULT_ICONS: Record<string, string>;
|
|
99
|
-
DEFAULT_DROPDOWN_DEFINITIONS: ImageStyleDropdownDefinition[];
|
|
100
|
-
};
|
|
101
|
-
export default _default;
|
|
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 image/imagestyle/utils
|
|
7
|
+
*/
|
|
8
|
+
import { type Editor, type PluginCollection } from 'ckeditor5/src/core';
|
|
9
|
+
import type { ImageStyleConfig, ImageStyleDropdownDefinition, ImageStyleOptionDefinition } from '../imageconfig';
|
|
10
|
+
/**
|
|
11
|
+
* Default image style options provided by the plugin that can be referred in the {@link module:image/imageconfig~ImageConfig#styles}
|
|
12
|
+
* configuration.
|
|
13
|
+
*
|
|
14
|
+
* There are available 5 styles focused on formatting:
|
|
15
|
+
*
|
|
16
|
+
* * **`'alignLeft'`** aligns the inline or block image to the left and wraps it with the text using the `image-style-align-left` class,
|
|
17
|
+
* * **`'alignRight'`** aligns the inline or block image to the right and wraps it with the text using the `image-style-align-right` class,
|
|
18
|
+
* * **`'alignCenter'`** centers the block image using the `image-style-align-center` class,
|
|
19
|
+
* * **`'alignBlockLeft'`** aligns the block image to the left using the `image-style-block-align-left` class,
|
|
20
|
+
* * **`'alignBlockRight'`** aligns the block image to the right using the `image-style-block-align-right` class,
|
|
21
|
+
*
|
|
22
|
+
* and 3 semantic styles:
|
|
23
|
+
*
|
|
24
|
+
* * **`'inline'`** is an inline image without any CSS class,
|
|
25
|
+
* * **`'block'`** is a block image without any CSS class,
|
|
26
|
+
* * **`'side'`** is a block image styled with the `image-style-side` CSS class.
|
|
27
|
+
*/
|
|
28
|
+
export declare const DEFAULT_OPTIONS: Record<string, ImageStyleOptionDefinition>;
|
|
29
|
+
/**
|
|
30
|
+
* Default image style icons provided by the plugin that can be referred in the {@link module:image/imageconfig~ImageConfig#styles}
|
|
31
|
+
* configuration.
|
|
32
|
+
*
|
|
33
|
+
* See {@link module:image/imageconfig~ImageStyleOptionDefinition#icon} to learn more.
|
|
34
|
+
*
|
|
35
|
+
* There are 7 default icons available: `'full'`, `'left'`, `'inlineLeft'`, `'center'`, `'right'`, `'inlineRight'`, and `'inline'`.
|
|
36
|
+
*/
|
|
37
|
+
export declare const DEFAULT_ICONS: Record<string, string>;
|
|
38
|
+
/**
|
|
39
|
+
* Default drop-downs provided by the plugin that can be referred in the {@link module:image/imageconfig~ImageConfig#toolbar}
|
|
40
|
+
* configuration. The drop-downs are containers for the {@link module:image/imageconfig~ImageStyleConfig#options image style options}.
|
|
41
|
+
*
|
|
42
|
+
* If both of the `ImageEditing` plugins are loaded, there are 2 predefined drop-downs available:
|
|
43
|
+
*
|
|
44
|
+
* * **`'imageStyle:wrapText'`**, which contains the `alignLeft` and `alignRight` options, that is,
|
|
45
|
+
* those that wraps the text around the image,
|
|
46
|
+
* * **`'imageStyle:breakText'`**, which contains the `alignBlockLeft`, `alignCenter` and `alignBlockRight` options, that is,
|
|
47
|
+
* those that breaks the text around the image.
|
|
48
|
+
*/
|
|
49
|
+
export declare const DEFAULT_DROPDOWN_DEFINITIONS: Array<ImageStyleDropdownDefinition>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns a list of the normalized and validated image style options.
|
|
52
|
+
*
|
|
53
|
+
* @param config
|
|
54
|
+
* @param config.isInlinePluginLoaded
|
|
55
|
+
* Determines whether the {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} plugin has been loaded.
|
|
56
|
+
* @param config.isBlockPluginLoaded
|
|
57
|
+
* Determines whether the {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} plugin has been loaded.
|
|
58
|
+
* @param config.configuredStyles
|
|
59
|
+
* The image styles configuration provided in the image styles {@link module:image/imageconfig~ImageConfig#styles configuration}
|
|
60
|
+
* as a default or custom value.
|
|
61
|
+
* @returns
|
|
62
|
+
* * Each of options contains a complete icon markup.
|
|
63
|
+
* * The image style options not supported by any of the loaded plugins are filtered out.
|
|
64
|
+
*/
|
|
65
|
+
declare function normalizeStyles(config: {
|
|
66
|
+
isInlinePluginLoaded: boolean;
|
|
67
|
+
isBlockPluginLoaded: boolean;
|
|
68
|
+
configuredStyles: ImageStyleConfig;
|
|
69
|
+
}): Array<ImageStyleOptionDefinition>;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the default image styles configuration depending on the loaded image editing plugins.
|
|
72
|
+
*
|
|
73
|
+
* @param isInlinePluginLoaded
|
|
74
|
+
* Determines whether the {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} plugin has been loaded.
|
|
75
|
+
*
|
|
76
|
+
* @param isBlockPluginLoaded
|
|
77
|
+
* Determines whether the {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} plugin has been loaded.
|
|
78
|
+
*
|
|
79
|
+
* @returns
|
|
80
|
+
* It returns an object with the lists of the image style options and groups defined as strings related to the
|
|
81
|
+
* {@link module:image/imagestyle/utils#DEFAULT_OPTIONS default options}
|
|
82
|
+
*/
|
|
83
|
+
declare function getDefaultStylesConfiguration(isBlockPluginLoaded: boolean, isInlinePluginLoaded: boolean): ImageStyleConfig;
|
|
84
|
+
/**
|
|
85
|
+
* Returns a list of the available predefined drop-downs' definitions depending on the loaded image editing plugins.
|
|
86
|
+
*/
|
|
87
|
+
declare function getDefaultDropdownDefinitions(pluginCollection: PluginCollection<Editor>): Array<ImageStyleDropdownDefinition>;
|
|
88
|
+
/**
|
|
89
|
+
* Displays a console warning with the 'image-style-configuration-definition-invalid' error.
|
|
90
|
+
*/
|
|
91
|
+
declare function warnInvalidStyle(info: object): void;
|
|
92
|
+
declare const _default: {
|
|
93
|
+
normalizeStyles: typeof normalizeStyles;
|
|
94
|
+
getDefaultStylesConfiguration: typeof getDefaultStylesConfiguration;
|
|
95
|
+
getDefaultDropdownDefinitions: typeof getDefaultDropdownDefinitions;
|
|
96
|
+
warnInvalidStyle: typeof warnInvalidStyle;
|
|
97
|
+
DEFAULT_OPTIONS: Record<string, ImageStyleOptionDefinition>;
|
|
98
|
+
DEFAULT_ICONS: Record<string, string>;
|
|
99
|
+
DEFAULT_DROPDOWN_DEFINITIONS: ImageStyleDropdownDefinition[];
|
|
100
|
+
};
|
|
101
|
+
export default _default;
|