@ckeditor/ckeditor5-image 36.0.0 → 37.0.0-alpha.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/build/image.js +1 -1
- package/package.json +40 -35
- package/src/autoimage.d.ts +53 -0
- package/src/autoimage.js +111 -160
- package/src/image/converters.d.ts +66 -0
- package/src/image/converters.js +200 -261
- package/src/image/imageblockediting.d.ts +57 -0
- package/src/image/imageblockediting.js +111 -155
- package/src/image/imageediting.d.ts +34 -0
- package/src/image/imageediting.js +53 -67
- package/src/image/imageinlineediting.d.ts +53 -0
- package/src/image/imageinlineediting.js +135 -180
- package/src/image/imageloadobserver.d.ts +44 -0
- package/src/image/imageloadobserver.js +28 -47
- package/src/image/imagetypecommand.d.ts +46 -0
- package/src/image/imagetypecommand.js +67 -95
- package/src/image/insertimagecommand.d.ts +72 -0
- package/src/image/insertimagecommand.js +95 -101
- package/src/image/replaceimagesourcecommand.d.ts +39 -0
- package/src/image/replaceimagesourcecommand.js +28 -33
- package/src/image/ui/utils.d.ts +25 -0
- package/src/image/ui/utils.js +25 -35
- package/src/image/utils.d.ts +52 -0
- package/src/image/utils.js +63 -90
- package/src/image.d.ts +38 -0
- package/src/image.js +13 -43
- package/src/imageblock.d.ts +35 -0
- package/src/imageblock.js +12 -21
- package/src/imagecaption/imagecaptionediting.d.ts +92 -0
- package/src/imagecaption/imagecaptionediting.js +203 -262
- package/src/imagecaption/imagecaptionui.d.ts +30 -0
- package/src/imagecaption/imagecaptionui.js +46 -63
- package/src/imagecaption/imagecaptionutils.d.ts +42 -0
- package/src/imagecaption/imagecaptionutils.js +51 -78
- package/src/imagecaption/toggleimagecaptioncommand.d.ts +71 -0
- package/src/imagecaption/toggleimagecaptioncommand.js +112 -138
- package/src/imagecaption.d.ts +29 -0
- package/src/imagecaption.js +12 -19
- package/src/imageconfig.d.ts +723 -0
- package/src/imageconfig.js +5 -0
- package/src/imageinline.d.ts +35 -0
- package/src/imageinline.js +12 -21
- package/src/imageinsert/imageinsertui.d.ts +49 -0
- package/src/imageinsert/imageinsertui.js +120 -158
- package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -0
- package/src/imageinsert/ui/imageinsertformrowview.js +37 -86
- package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -0
- package/src/imageinsert/ui/imageinsertpanelview.js +148 -258
- package/src/imageinsert/utils.d.ts +26 -0
- package/src/imageinsert/utils.js +42 -58
- package/src/imageinsert.d.ts +35 -0
- package/src/imageinsert.js +13 -84
- package/src/imageinsertviaurl.d.ts +34 -0
- package/src/imageinsertviaurl.js +12 -18
- package/src/imageresize/imageresizebuttons.d.ts +66 -0
- package/src/imageresize/imageresizebuttons.js +190 -255
- package/src/imageresize/imageresizeediting.d.ts +42 -0
- package/src/imageresize/imageresizeediting.js +100 -125
- package/src/imageresize/imageresizehandles.d.ts +30 -0
- package/src/imageresize/imageresizehandles.js +91 -123
- package/src/imageresize/resizeimagecommand.d.ts +47 -0
- package/src/imageresize/resizeimagecommand.js +48 -55
- package/src/imageresize.d.ts +29 -0
- package/src/imageresize.js +12 -209
- package/src/imagestyle/converters.d.ts +24 -0
- package/src/imagestyle/converters.js +60 -78
- package/src/imagestyle/imagestylecommand.d.ts +70 -0
- package/src/imagestyle/imagestylecommand.js +88 -124
- package/src/imagestyle/imagestyleediting.d.ts +54 -0
- package/src/imagestyle/imagestyleediting.js +90 -137
- package/src/imagestyle/imagestyleui.d.ts +60 -0
- package/src/imagestyle/imagestyleui.js +169 -277
- package/src/imagestyle/utils.d.ts +61 -0
- package/src/imagestyle/utils.js +253 -306
- package/src/imagestyle.d.ts +35 -0
- package/src/imagestyle.js +13 -261
- package/src/imagetextalternative/imagetextalternativecommand.d.ts +39 -0
- package/src/imagetextalternative/imagetextalternativecommand.js +31 -47
- package/src/imagetextalternative/imagetextalternativeediting.d.ts +32 -0
- package/src/imagetextalternative/imagetextalternativeediting.js +18 -25
- package/src/imagetextalternative/imagetextalternativeui.d.ts +72 -0
- package/src/imagetextalternative/imagetextalternativeui.js +156 -219
- package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -0
- package/src/imagetextalternative/ui/textalternativeformview.js +103 -192
- package/src/imagetextalternative.d.ts +32 -0
- package/src/imagetextalternative.js +12 -18
- package/src/imagetoolbar.d.ts +38 -0
- package/src/imagetoolbar.js +31 -77
- package/src/imageupload/imageuploadediting.d.ts +114 -0
- package/src/imageupload/imageuploadediting.js +308 -427
- package/src/imageupload/imageuploadprogress.d.ts +47 -0
- package/src/imageupload/imageuploadprogress.js +180 -261
- package/src/imageupload/imageuploadui.d.ts +29 -0
- package/src/imageupload/imageuploadui.js +41 -57
- package/src/imageupload/uploadimagecommand.d.ts +65 -0
- package/src/imageupload/uploadimagecommand.js +73 -87
- package/src/imageupload/utils.d.ts +33 -0
- package/src/imageupload/utils.js +87 -112
- package/src/imageupload.d.ts +34 -0
- package/src/imageupload.js +12 -61
- package/src/imageutils.d.ts +108 -0
- package/src/imageutils.js +233 -329
- package/src/index.d.ts +31 -0
- package/src/index.js +0 -2
- package/src/pictureediting.d.ts +86 -0
- package/src/pictureediting.js +101 -120
|
@@ -2,67 +2,60 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module image/imageresize/resizeimagecommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Command } from 'ckeditor5/src/core';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* The resize image command. Currently, it only supports the width attribute.
|
|
14
|
-
*
|
|
15
|
-
* @extends module:core/command~Command
|
|
16
11
|
*/
|
|
17
12
|
export default class ResizeImageCommand extends Command {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
}
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
refresh() {
|
|
17
|
+
const editor = this.editor;
|
|
18
|
+
const imageUtils = editor.plugins.get('ImageUtils');
|
|
19
|
+
const element = imageUtils.getClosestSelectedImageElement(editor.model.document.selection);
|
|
20
|
+
this.isEnabled = !!element;
|
|
21
|
+
if (!element || !element.hasAttribute('width')) {
|
|
22
|
+
this.value = null;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.value = {
|
|
26
|
+
width: element.getAttribute('width'),
|
|
27
|
+
height: null
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Executes the command.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* // Sets the width to 50%:
|
|
36
|
+
* editor.execute( 'resizeImage', { width: '50%' } );
|
|
37
|
+
*
|
|
38
|
+
* // Removes the width attribute:
|
|
39
|
+
* editor.execute( 'resizeImage', { width: null } );
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param options
|
|
43
|
+
* @param options.width The new width of the image.
|
|
44
|
+
* @fires execute
|
|
45
|
+
*/
|
|
46
|
+
execute(options) {
|
|
47
|
+
const editor = this.editor;
|
|
48
|
+
const model = editor.model;
|
|
49
|
+
const imageUtils = editor.plugins.get('ImageUtils');
|
|
50
|
+
const imageElement = imageUtils.getClosestSelectedImageElement(model.document.selection);
|
|
51
|
+
this.value = {
|
|
52
|
+
width: options.width,
|
|
53
|
+
height: null
|
|
54
|
+
};
|
|
55
|
+
if (imageElement) {
|
|
56
|
+
model.change(writer => {
|
|
57
|
+
writer.setAttribute('width', options.width, imageElement);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
68
61
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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/imageresize
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
|
|
9
|
+
import '../theme/imageresize.css';
|
|
10
|
+
/**
|
|
11
|
+
* The image resize plugin.
|
|
12
|
+
*
|
|
13
|
+
* It adds a possibility to resize each image using handles.
|
|
14
|
+
*/
|
|
15
|
+
export default class ImageResize extends Plugin {
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
static get requires(): PluginDependencies;
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
static get pluginName(): 'ImageResize';
|
|
24
|
+
}
|
|
25
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
26
|
+
interface PluginsMap {
|
|
27
|
+
[ImageResize.pluginName]: ImageResize;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/imageresize.js
CHANGED
|
@@ -2,227 +2,30 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module image/imageresize
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
9
|
import ImageResizeButtons from './imageresize/imageresizebuttons';
|
|
12
10
|
import ImageResizeEditing from './imageresize/imageresizeediting';
|
|
13
11
|
import ImageResizeHandles from './imageresize/imageresizehandles';
|
|
14
|
-
|
|
15
12
|
import '../theme/imageresize.css';
|
|
16
|
-
|
|
17
13
|
/**
|
|
18
14
|
* The image resize plugin.
|
|
19
15
|
*
|
|
20
16
|
* It adds a possibility to resize each image using handles.
|
|
21
|
-
*
|
|
22
|
-
* @extends module:core/plugin~Plugin
|
|
23
17
|
*/
|
|
24
18
|
export default class ImageResize extends Plugin {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get requires() {
|
|
23
|
+
return [ImageResizeEditing, ImageResizeHandles, ImageResizeButtons];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
static get pluginName() {
|
|
29
|
+
return 'ImageResize';
|
|
30
|
+
}
|
|
38
31
|
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The available options are `'px'` or `'%'`.
|
|
42
|
-
*
|
|
43
|
-
* Determines the size unit applied to the resized image.
|
|
44
|
-
*
|
|
45
|
-
* ClassicEditor
|
|
46
|
-
* .create( editorElement, {
|
|
47
|
-
* image: {
|
|
48
|
-
* resizeUnit: 'px'
|
|
49
|
-
* }
|
|
50
|
-
* } )
|
|
51
|
-
* .then( ... )
|
|
52
|
-
* .catch( ... );
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* This option is used by the {@link module:image/imageresize~ImageResize} feature.
|
|
56
|
-
*
|
|
57
|
-
* @default '%'
|
|
58
|
-
* @member {String} module:image/image~ImageConfig#resizeUnit
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* The image resize options.
|
|
63
|
-
*
|
|
64
|
-
* Each option should have at least these two properties:
|
|
65
|
-
*
|
|
66
|
-
* * name: The name of the UI component registered in the global
|
|
67
|
-
* {@link module:core/editor/editorui~EditorUI#componentFactory component factory} of the editor,
|
|
68
|
-
* representing the button a user can click to change the size of an image,
|
|
69
|
-
* * value: An actual image width applied when a user clicks the mentioned button
|
|
70
|
-
* ({@link module:image/imageresize/resizeimagecommand~ResizeImageCommand} gets executed).
|
|
71
|
-
* The value property is combined with the {@link module:image/image~ImageConfig#resizeUnit `config.image.resizeUnit`} (`%` by default).
|
|
72
|
-
* For instance: `value: '50'` and `resizeUnit: '%'` will render as `'50%'` in the UI.
|
|
73
|
-
*
|
|
74
|
-
* **Resetting the image size**
|
|
75
|
-
*
|
|
76
|
-
* If you want to set an option that will reset image to its original size, you need to pass a `null` value
|
|
77
|
-
* to one of the options. The `:original` token is not mandatory, you can call it anything you wish, but it must reflect
|
|
78
|
-
* in the standalone buttons configuration for the image toolbar.
|
|
79
|
-
*
|
|
80
|
-
* ClassicEditor
|
|
81
|
-
* .create( editorElement, {
|
|
82
|
-
* image: {
|
|
83
|
-
* resizeUnit: "%",
|
|
84
|
-
* resizeOptions: [ {
|
|
85
|
-
* name: 'resizeImage:original',
|
|
86
|
-
* value: null
|
|
87
|
-
* },
|
|
88
|
-
* {
|
|
89
|
-
* name: 'resizeImage:50',
|
|
90
|
-
* value: '50'
|
|
91
|
-
* },
|
|
92
|
-
* {
|
|
93
|
-
* name: 'resizeImage:75',
|
|
94
|
-
* value: '75'
|
|
95
|
-
* } ]
|
|
96
|
-
* }
|
|
97
|
-
* } )
|
|
98
|
-
* .then( ... )
|
|
99
|
-
* .catch( ... );
|
|
100
|
-
*
|
|
101
|
-
* **Resizing images using a dropdown**
|
|
102
|
-
*
|
|
103
|
-
* With resize options defined, you can decide whether you want to display them as a dropdown or as standalone buttons.
|
|
104
|
-
* For the dropdown, you need to pass only the `resizeImage` token to the
|
|
105
|
-
{@link module:image/image~ImageConfig#toolbar `config.image.toolbar`}. The dropdown contains all defined options by default:
|
|
106
|
-
*
|
|
107
|
-
* ClassicEditor
|
|
108
|
-
* .create( editorElement, {
|
|
109
|
-
* image: {
|
|
110
|
-
* resizeUnit: "%",
|
|
111
|
-
* resizeOptions: [ {
|
|
112
|
-
* name: 'resizeImage:original',
|
|
113
|
-
* value: null
|
|
114
|
-
* },
|
|
115
|
-
* {
|
|
116
|
-
* name: 'resizeImage:50',
|
|
117
|
-
* value: '50'
|
|
118
|
-
* },
|
|
119
|
-
* {
|
|
120
|
-
* name: 'resizeImage:75',
|
|
121
|
-
* value: '75'
|
|
122
|
-
* } ],
|
|
123
|
-
* toolbar: [ 'resizeImage', ... ],
|
|
124
|
-
* }
|
|
125
|
-
* } )
|
|
126
|
-
* .then( ... )
|
|
127
|
-
* .catch( ... );
|
|
128
|
-
*
|
|
129
|
-
* **Resizing images using individual buttons**
|
|
130
|
-
*
|
|
131
|
-
* If you want to have separate buttons for {@link module:image/imageresize/imageresizebuttons~ImageResizeOption each option},
|
|
132
|
-
* pass their names to the {@link module:image/image~ImageConfig#toolbar `config.image.toolbar`} instead. Please keep in mind
|
|
133
|
-
* that this time **you must define the additional
|
|
134
|
-
* {@link module:image/imageresize/imageresizebuttons~ImageResizeOption `icon` property}**:
|
|
135
|
-
*
|
|
136
|
-
* ClassicEditor
|
|
137
|
-
* .create( editorElement, {
|
|
138
|
-
* image: {
|
|
139
|
-
* resizeUnit: "%",
|
|
140
|
-
* resizeOptions: [ {
|
|
141
|
-
* name: 'resizeImage:original',
|
|
142
|
-
* value: null,
|
|
143
|
-
* icon: 'original'
|
|
144
|
-
* },
|
|
145
|
-
* {
|
|
146
|
-
* name: 'resizeImage:25',
|
|
147
|
-
* value: '25',
|
|
148
|
-
* icon: 'small'
|
|
149
|
-
* },
|
|
150
|
-
* {
|
|
151
|
-
* name: 'resizeImage:50',
|
|
152
|
-
* value: '50',
|
|
153
|
-
* icon: 'medium'
|
|
154
|
-
* },
|
|
155
|
-
* {
|
|
156
|
-
* name: 'resizeImage:75',
|
|
157
|
-
* value: '75',
|
|
158
|
-
* icon: 'large'
|
|
159
|
-
* } ],
|
|
160
|
-
* toolbar: [ 'resizeImage:25', 'resizeImage:50', 'resizeImage:75', 'resizeImage:original', ... ],
|
|
161
|
-
* }
|
|
162
|
-
* } )
|
|
163
|
-
* .then( ... )
|
|
164
|
-
* .catch( ... );
|
|
165
|
-
*
|
|
166
|
-
* **Customizing resize button labels**
|
|
167
|
-
*
|
|
168
|
-
* You can set your own label for each resize button. To do that, add the `label` property like in the example below.
|
|
169
|
-
*
|
|
170
|
-
* * When using the **dropdown**, the labels are displayed on the list of all options when you open the dropdown.
|
|
171
|
-
* * When using **standalone buttons**, the labels will are displayed as tooltips when a user hovers over the button.
|
|
172
|
-
*
|
|
173
|
-
* ClassicEditor
|
|
174
|
-
* .create( editorElement, {
|
|
175
|
-
* image: {
|
|
176
|
-
* resizeUnit: "%",
|
|
177
|
-
* resizeOptions: [ {
|
|
178
|
-
* name: 'resizeImage:original',
|
|
179
|
-
* value: null,
|
|
180
|
-
* label: 'Original size'
|
|
181
|
-
* // Note: add the "icon" property if you're configuring a standalone button.
|
|
182
|
-
* },
|
|
183
|
-
* {
|
|
184
|
-
* name: 'resizeImage:50',
|
|
185
|
-
* value: '50',
|
|
186
|
-
* label: 'Medium size'
|
|
187
|
-
* // Note: add the "icon" property if you're configuring a standalone button.
|
|
188
|
-
* },
|
|
189
|
-
* {
|
|
190
|
-
* name: 'resizeImage:75',
|
|
191
|
-
* value: '75',
|
|
192
|
-
* label: 'Large size'
|
|
193
|
-
* // Note: add the "icon" property if you're configuring a standalone button.
|
|
194
|
-
* } ]
|
|
195
|
-
* }
|
|
196
|
-
* } )
|
|
197
|
-
* .then( ... )
|
|
198
|
-
* .catch( ... );
|
|
199
|
-
*
|
|
200
|
-
* **Default value**
|
|
201
|
-
*
|
|
202
|
-
* The following configuration is used by default:
|
|
203
|
-
*
|
|
204
|
-
* resizeOptions = [
|
|
205
|
-
* {
|
|
206
|
-
* name: 'resizeImage:original',
|
|
207
|
-
* value: null,
|
|
208
|
-
* icon: 'original'
|
|
209
|
-
* },
|
|
210
|
-
* {
|
|
211
|
-
* name: 'resizeImage:25',
|
|
212
|
-
* value: '25',
|
|
213
|
-
* icon: 'small'
|
|
214
|
-
* },
|
|
215
|
-
* {
|
|
216
|
-
* name: 'resizeImage:50',
|
|
217
|
-
* value: '50',
|
|
218
|
-
* icon: 'medium'
|
|
219
|
-
* },
|
|
220
|
-
* {
|
|
221
|
-
* name: 'resizeImage:75',
|
|
222
|
-
* value: '75',
|
|
223
|
-
* icon: 'large'
|
|
224
|
-
* }
|
|
225
|
-
* ];
|
|
226
|
-
*
|
|
227
|
-
* @member {Array.<module:image/imageresize/imageresizebuttons~ImageResizeOption>} module:image/image~ImageConfig#resizeOptions
|
|
228
|
-
*/
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
import type { DowncastAttributeEvent, UpcastElementEvent } from 'ckeditor5/src/engine';
|
|
6
|
+
import { type GetCallback } from 'ckeditor5/src/utils';
|
|
7
|
+
import type { ImageStyleOptionDefinition } from '../imageconfig';
|
|
8
|
+
/**
|
|
9
|
+
* @module image/imagestyle/converters
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Returns a converter for the `imageStyle` attribute. It can be used for adding, changing and removing the attribute.
|
|
13
|
+
*
|
|
14
|
+
* @param styles An array containing available image style options.
|
|
15
|
+
* @returns A model-to-view attribute converter.
|
|
16
|
+
*/
|
|
17
|
+
export declare function modelToViewStyleAttribute(styles: Array<ImageStyleOptionDefinition>): GetCallback<DowncastAttributeEvent>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a view-to-model converter converting image CSS classes to a proper value in the model.
|
|
20
|
+
*
|
|
21
|
+
* @param styles Image style options for which the converter is created.
|
|
22
|
+
* @returns A view-to-model converter.
|
|
23
|
+
*/
|
|
24
|
+
export declare function viewToModelStyleAttribute(styles: Array<ImageStyleOptionDefinition>): GetCallback<UpcastElementEvent>;
|
|
@@ -2,96 +2,78 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
import { first } from 'ckeditor5/src/utils';
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* @module image/imagestyle/converters
|
|
10
8
|
*/
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Returns a converter for the `imageStyle` attribute. It can be used for adding, changing and removing the attribute.
|
|
14
11
|
*
|
|
15
|
-
* @param
|
|
16
|
-
*
|
|
17
|
-
* @returns {Function} A model-to-view attribute converter.
|
|
12
|
+
* @param styles An array containing available image style options.
|
|
13
|
+
* @returns A model-to-view attribute converter.
|
|
18
14
|
*/
|
|
19
|
-
export function modelToViewStyleAttribute(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if ( newStyle ) {
|
|
37
|
-
viewWriter.addClass( newStyle.className, viewElement );
|
|
38
|
-
}
|
|
39
|
-
};
|
|
15
|
+
export function modelToViewStyleAttribute(styles) {
|
|
16
|
+
return (evt, data, conversionApi) => {
|
|
17
|
+
if (!conversionApi.consumable.consume(data.item, evt.name)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// Check if there is class name associated with given value.
|
|
21
|
+
const newStyle = getStyleDefinitionByName(data.attributeNewValue, styles);
|
|
22
|
+
const oldStyle = getStyleDefinitionByName(data.attributeOldValue, styles);
|
|
23
|
+
const viewElement = conversionApi.mapper.toViewElement(data.item);
|
|
24
|
+
const viewWriter = conversionApi.writer;
|
|
25
|
+
if (oldStyle) {
|
|
26
|
+
viewWriter.removeClass(oldStyle.className, viewElement);
|
|
27
|
+
}
|
|
28
|
+
if (newStyle) {
|
|
29
|
+
viewWriter.addClass(newStyle.className, viewElement);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
40
32
|
}
|
|
41
|
-
|
|
42
33
|
/**
|
|
43
34
|
* Returns a view-to-model converter converting image CSS classes to a proper value in the model.
|
|
44
35
|
*
|
|
45
|
-
* @param
|
|
46
|
-
*
|
|
47
|
-
* @returns {Function} A view-to-model converter.
|
|
36
|
+
* @param styles Image style options for which the converter is created.
|
|
37
|
+
* @returns A view-to-model converter.
|
|
48
38
|
*/
|
|
49
|
-
export function viewToModelStyleAttribute(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// And convert this style to model attribute.
|
|
80
|
-
conversionApi.writer.setAttribute( 'imageStyle', style.name, modelImageElement );
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
39
|
+
export function viewToModelStyleAttribute(styles) {
|
|
40
|
+
// Convert only non–default styles.
|
|
41
|
+
const nonDefaultStyles = {
|
|
42
|
+
imageInline: styles.filter(style => !style.isDefault && style.modelElements.includes('imageInline')),
|
|
43
|
+
imageBlock: styles.filter(style => !style.isDefault && style.modelElements.includes('imageBlock'))
|
|
44
|
+
};
|
|
45
|
+
return (evt, data, conversionApi) => {
|
|
46
|
+
if (!data.modelRange) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const viewElement = data.viewItem;
|
|
50
|
+
const modelImageElement = first(data.modelRange.getItems());
|
|
51
|
+
// Run this converter only if an image has been found in the model.
|
|
52
|
+
// In some cases it may not be found (for example if we run this on a figure with different type than image).
|
|
53
|
+
if (!modelImageElement) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// ...and the `imageStyle` attribute is allowed for that element, otherwise stop conversion early.
|
|
57
|
+
if (!conversionApi.schema.checkAttribute(modelImageElement, 'imageStyle')) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Convert styles one by one.
|
|
61
|
+
for (const style of nonDefaultStyles[modelImageElement.name]) {
|
|
62
|
+
// Try to consume class corresponding with the style.
|
|
63
|
+
if (conversionApi.consumable.consume(viewElement, { classes: style.className })) {
|
|
64
|
+
// And convert this style to model attribute.
|
|
65
|
+
conversionApi.writer.setAttribute('imageStyle', style.name, modelImageElement);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
84
69
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return style;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns the style with a given `name` from an array of styles.
|
|
72
|
+
*/
|
|
73
|
+
function getStyleDefinitionByName(name, styles) {
|
|
74
|
+
for (const style of styles) {
|
|
75
|
+
if (style.name === name) {
|
|
76
|
+
return style;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
97
79
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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/imagestylecommand
|
|
7
|
+
*/
|
|
8
|
+
import type { Element } from 'ckeditor5/src/engine';
|
|
9
|
+
import { Command, type Editor } from 'ckeditor5/src/core';
|
|
10
|
+
import type { ImageStyleOptionDefinition } from '../imageconfig';
|
|
11
|
+
/**
|
|
12
|
+
* The image style command. It is used to apply {@link module:image/imageconfig~ImageStyleConfig#options image style option}
|
|
13
|
+
* to a selected image.
|
|
14
|
+
*
|
|
15
|
+
* **Note**: Executing this command may change the image model element if the desired style requires an image of a different
|
|
16
|
+
* type. See {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand#execute} to learn more.
|
|
17
|
+
*/
|
|
18
|
+
export default class ImageStyleCommand extends Command {
|
|
19
|
+
/**
|
|
20
|
+
* An object containing names of default style options for the inline and block images.
|
|
21
|
+
* If there is no default style option for the given image type in the configuration,
|
|
22
|
+
* the name will be `false`.
|
|
23
|
+
*/
|
|
24
|
+
private _defaultStyles;
|
|
25
|
+
/**
|
|
26
|
+
* The styles handled by this command.
|
|
27
|
+
*/
|
|
28
|
+
private _styles;
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of the image style command. When executed, the command applies one of
|
|
31
|
+
* {@link module:image/imageconfig~ImageStyleConfig#options style options} to the currently selected image.
|
|
32
|
+
*
|
|
33
|
+
* @param editor The editor instance.
|
|
34
|
+
* @param styles The style options that this command supports.
|
|
35
|
+
*/
|
|
36
|
+
constructor(editor: Editor, styles: Array<ImageStyleOptionDefinition>);
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
refresh(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Executes the command and applies the style to the currently selected image:
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* editor.execute( 'imageStyle', { value: 'side' } );
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* **Note**: Executing this command may change the image model element if the desired style requires an image
|
|
49
|
+
* of a different type. Learn more about {@link module:image/imageconfig~ImageStyleOptionDefinition#modelElements model element}
|
|
50
|
+
* configuration for the style option.
|
|
51
|
+
*
|
|
52
|
+
* @param options.value The name of the style (as configured in {@link module:image/imageconfig~ImageStyleConfig#options}).
|
|
53
|
+
* @fires execute
|
|
54
|
+
*/
|
|
55
|
+
execute(options?: {
|
|
56
|
+
value?: string;
|
|
57
|
+
}): void;
|
|
58
|
+
/**
|
|
59
|
+
* Returns `true` if requested style change would trigger the image type change.
|
|
60
|
+
*
|
|
61
|
+
* @param requestedStyle The name of the style (as configured in {@link module:image/imageconfig~ImageStyleConfig#options}).
|
|
62
|
+
* @param imageElement The image model element.
|
|
63
|
+
*/
|
|
64
|
+
shouldConvertImageType(requestedStyle: string, imageElement: Element): boolean;
|
|
65
|
+
}
|
|
66
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
67
|
+
interface CommandsMap {
|
|
68
|
+
imageStyle: ImageStyleCommand;
|
|
69
|
+
}
|
|
70
|
+
}
|