@ckeditor/ckeditor5-image 47.6.1 → 48.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/LICENSE.md +1 -1
- package/ckeditor5-metadata.json +25 -25
- package/{src → dist}/autoimage.d.ts +4 -4
- package/{src → dist}/image/converters.d.ts +1 -1
- package/{src → dist}/image/imageblockediting.d.ts +2 -2
- package/{src → dist}/image/imageediting.d.ts +1 -1
- package/{src → dist}/image/imageinlineediting.d.ts +2 -2
- package/{src → dist}/image/imageloadobserver.d.ts +1 -1
- package/{src → dist}/image/imageplaceholder.d.ts +1 -1
- package/{src → dist}/image/imagetypecommand.d.ts +2 -2
- package/{src → dist}/image/insertimagecommand.d.ts +2 -2
- package/{src → dist}/image/replaceimagesourcecommand.d.ts +2 -2
- package/{src → dist}/image/ui/utils.d.ts +2 -2
- package/{src → dist}/image/utils.d.ts +2 -2
- package/{src → dist}/image.d.ts +1 -1
- package/{src → dist}/imageblock.d.ts +2 -2
- package/{src → dist}/imagecaption/imagecaptionediting.d.ts +2 -2
- package/{src → dist}/imagecaption/imagecaptionui.d.ts +1 -1
- package/{src → dist}/imagecaption/imagecaptionutils.d.ts +2 -2
- package/{src → dist}/imagecaption/toggleimagecaptioncommand.d.ts +1 -1
- package/{src → dist}/imagecaption.d.ts +1 -1
- package/{src → dist}/imageconfig.d.ts +25 -16
- package/{src → dist}/imageinline.d.ts +2 -2
- package/{src → dist}/imageinsert/imageinsertui.d.ts +3 -3
- package/{src → dist}/imageinsert/imageinsertviaurlui.d.ts +2 -2
- package/{src → dist}/imageinsert/ui/imageinsertformview.d.ts +2 -2
- package/{src → dist}/imageinsert/ui/imageinserturlview.d.ts +2 -2
- package/{src → dist}/imageinsert.d.ts +1 -1
- package/{src → dist}/imageinsertviaurl.d.ts +1 -1
- package/{src → dist}/imageresize/imagecustomresizeui.d.ts +2 -2
- package/{src → dist}/imageresize/imageresizebuttons.d.ts +1 -1
- package/{src → dist}/imageresize/imageresizeediting.d.ts +1 -1
- package/{src → dist}/imageresize/imageresizehandles.d.ts +2 -2
- package/{src → dist}/imageresize/resizeimagecommand.d.ts +1 -1
- package/{src → dist}/imageresize/ui/imagecustomresizeformview.d.ts +2 -4
- package/{src → dist}/imageresize/utils/getselectedimageeditornodes.d.ts +2 -2
- package/{src → dist}/imageresize/utils/getselectedimagepossibleresizerange.d.ts +1 -1
- package/{src → dist}/imageresize/utils/getselectedimagewidthinunits.d.ts +1 -1
- package/{src → dist}/imageresize.d.ts +1 -1
- package/{src → dist}/imagesizeattributes.d.ts +1 -1
- package/{src → dist}/imagestyle/converters.d.ts +2 -2
- package/{src → dist}/imagestyle/imagestylecommand.d.ts +2 -2
- package/{src → dist}/imagestyle/imagestyleediting.d.ts +1 -1
- package/{src → dist}/imagestyle/imagestyleui.d.ts +1 -1
- package/{src → dist}/imagestyle/utils.d.ts +1 -1
- package/{src → dist}/imagestyle.d.ts +1 -1
- package/{src → dist}/imagetextalternative/imagetextalternativecommand.d.ts +1 -1
- package/{src → dist}/imagetextalternative/imagetextalternativeediting.d.ts +1 -1
- package/{src → dist}/imagetextalternative/imagetextalternativeui.d.ts +2 -2
- package/{src → dist}/imagetextalternative/ui/textalternativeformview.d.ts +2 -4
- package/{src → dist}/imagetextalternative.d.ts +1 -1
- package/{src → dist}/imagetoolbar.d.ts +2 -2
- package/{src → dist}/imageupload/imageuploadediting.d.ts +5 -5
- package/{src → dist}/imageupload/imageuploadprogress.d.ts +1 -1
- package/{src → dist}/imageupload/imageuploadui.d.ts +1 -1
- package/{src → dist}/imageupload/uploadimagecommand.d.ts +2 -2
- package/{src → dist}/imageupload/utils.d.ts +1 -1
- package/{src → dist}/imageupload.d.ts +1 -1
- package/{src → dist}/imageutils.d.ts +2 -2
- package/dist/index-content.css +97 -100
- package/dist/index-editor.css +313 -190
- package/dist/index.css +388 -458
- package/dist/index.css.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/{src → dist}/pictureediting.d.ts +1 -1
- package/package.json +29 -53
- package/build/image.js +0 -5
- package/build/translations/af.js +0 -1
- package/build/translations/ar.js +0 -1
- package/build/translations/ast.js +0 -1
- package/build/translations/az.js +0 -1
- package/build/translations/be.js +0 -1
- package/build/translations/bg.js +0 -1
- package/build/translations/bn.js +0 -1
- package/build/translations/bs.js +0 -1
- package/build/translations/ca.js +0 -1
- package/build/translations/cs.js +0 -1
- package/build/translations/da.js +0 -1
- package/build/translations/de-ch.js +0 -1
- package/build/translations/de.js +0 -1
- package/build/translations/el.js +0 -1
- package/build/translations/en-au.js +0 -1
- package/build/translations/en-gb.js +0 -1
- package/build/translations/eo.js +0 -1
- package/build/translations/es-co.js +0 -1
- package/build/translations/es.js +0 -1
- package/build/translations/et.js +0 -1
- package/build/translations/eu.js +0 -1
- package/build/translations/fa.js +0 -1
- package/build/translations/fi.js +0 -1
- package/build/translations/fr.js +0 -1
- package/build/translations/gl.js +0 -1
- package/build/translations/gu.js +0 -1
- package/build/translations/he.js +0 -1
- package/build/translations/hi.js +0 -1
- package/build/translations/hr.js +0 -1
- package/build/translations/hu.js +0 -1
- package/build/translations/hy.js +0 -1
- package/build/translations/id.js +0 -1
- package/build/translations/it.js +0 -1
- package/build/translations/ja.js +0 -1
- package/build/translations/jv.js +0 -1
- package/build/translations/kk.js +0 -1
- package/build/translations/km.js +0 -1
- package/build/translations/kn.js +0 -1
- package/build/translations/ko.js +0 -1
- package/build/translations/ku.js +0 -1
- package/build/translations/lt.js +0 -1
- package/build/translations/lv.js +0 -1
- package/build/translations/ms.js +0 -1
- package/build/translations/nb.js +0 -1
- package/build/translations/ne.js +0 -1
- package/build/translations/nl.js +0 -1
- package/build/translations/no.js +0 -1
- package/build/translations/oc.js +0 -1
- package/build/translations/pl.js +0 -1
- package/build/translations/pt-br.js +0 -1
- package/build/translations/pt.js +0 -1
- package/build/translations/ro.js +0 -1
- package/build/translations/ru.js +0 -1
- package/build/translations/si.js +0 -1
- package/build/translations/sk.js +0 -1
- package/build/translations/sl.js +0 -1
- package/build/translations/sq.js +0 -1
- package/build/translations/sr-latn.js +0 -1
- package/build/translations/sr.js +0 -1
- package/build/translations/sv.js +0 -1
- package/build/translations/th.js +0 -1
- package/build/translations/ti.js +0 -1
- package/build/translations/tk.js +0 -1
- package/build/translations/tr.js +0 -1
- package/build/translations/tt.js +0 -1
- package/build/translations/ug.js +0 -1
- package/build/translations/uk.js +0 -1
- package/build/translations/ur.js +0 -1
- package/build/translations/uz.js +0 -1
- package/build/translations/vi.js +0 -1
- package/build/translations/zh-cn.js +0 -1
- package/build/translations/zh.js +0 -1
- package/lang/contexts.json +0 -48
- package/lang/translations/af.po +0 -196
- package/lang/translations/ar.po +0 -196
- package/lang/translations/ast.po +0 -196
- package/lang/translations/az.po +0 -196
- package/lang/translations/be.po +0 -196
- package/lang/translations/bg.po +0 -196
- package/lang/translations/bn.po +0 -196
- package/lang/translations/bs.po +0 -196
- package/lang/translations/ca.po +0 -196
- package/lang/translations/cs.po +0 -196
- package/lang/translations/da.po +0 -196
- package/lang/translations/de-ch.po +0 -196
- package/lang/translations/de.po +0 -196
- package/lang/translations/el.po +0 -196
- package/lang/translations/en-au.po +0 -196
- package/lang/translations/en-gb.po +0 -196
- package/lang/translations/en.po +0 -196
- package/lang/translations/eo.po +0 -196
- package/lang/translations/es-co.po +0 -196
- package/lang/translations/es.po +0 -196
- package/lang/translations/et.po +0 -196
- package/lang/translations/eu.po +0 -196
- package/lang/translations/fa.po +0 -196
- package/lang/translations/fi.po +0 -196
- package/lang/translations/fr.po +0 -196
- package/lang/translations/gl.po +0 -196
- package/lang/translations/gu.po +0 -196
- package/lang/translations/he.po +0 -196
- package/lang/translations/hi.po +0 -196
- package/lang/translations/hr.po +0 -196
- package/lang/translations/hu.po +0 -196
- package/lang/translations/hy.po +0 -196
- package/lang/translations/id.po +0 -196
- package/lang/translations/it.po +0 -196
- package/lang/translations/ja.po +0 -196
- package/lang/translations/jv.po +0 -196
- package/lang/translations/kk.po +0 -196
- package/lang/translations/km.po +0 -196
- package/lang/translations/kn.po +0 -196
- package/lang/translations/ko.po +0 -196
- package/lang/translations/ku.po +0 -196
- package/lang/translations/lt.po +0 -196
- package/lang/translations/lv.po +0 -196
- package/lang/translations/ms.po +0 -196
- package/lang/translations/nb.po +0 -196
- package/lang/translations/ne.po +0 -196
- package/lang/translations/nl.po +0 -196
- package/lang/translations/no.po +0 -196
- package/lang/translations/oc.po +0 -196
- package/lang/translations/pl.po +0 -196
- package/lang/translations/pt-br.po +0 -196
- package/lang/translations/pt.po +0 -196
- package/lang/translations/ro.po +0 -196
- package/lang/translations/ru.po +0 -196
- package/lang/translations/si.po +0 -196
- package/lang/translations/sk.po +0 -196
- package/lang/translations/sl.po +0 -196
- package/lang/translations/sq.po +0 -196
- package/lang/translations/sr-latn.po +0 -196
- package/lang/translations/sr.po +0 -196
- package/lang/translations/sv.po +0 -196
- package/lang/translations/th.po +0 -196
- package/lang/translations/ti.po +0 -196
- package/lang/translations/tk.po +0 -196
- package/lang/translations/tr.po +0 -196
- package/lang/translations/tt.po +0 -196
- package/lang/translations/ug.po +0 -196
- package/lang/translations/uk.po +0 -196
- package/lang/translations/ur.po +0 -196
- package/lang/translations/uz.po +0 -196
- package/lang/translations/vi.po +0 -196
- package/lang/translations/zh-cn.po +0 -196
- package/lang/translations/zh.po +0 -196
- package/src/augmentation.js +0 -5
- package/src/autoimage.js +0 -148
- package/src/image/converters.js +0 -236
- package/src/image/imageblockediting.js +0 -159
- package/src/image/imageediting.js +0 -69
- package/src/image/imageinlineediting.js +0 -178
- package/src/image/imageloadobserver.js +0 -52
- package/src/image/imageplaceholder.js +0 -119
- package/src/image/imagetypecommand.js +0 -84
- package/src/image/insertimagecommand.js +0 -125
- package/src/image/replaceimagesourcecommand.js +0 -75
- package/src/image/ui/utils.js +0 -46
- package/src/image/utils.js +0 -125
- package/src/image.js +0 -44
- package/src/imageblock.js +0 -44
- package/src/imagecaption/imagecaptionediting.js +0 -238
- package/src/imagecaption/imagecaptionui.js +0 -68
- package/src/imagecaption/imagecaptionutils.js +0 -68
- package/src/imagecaption/toggleimagecaptioncommand.js +0 -138
- package/src/imagecaption.js +0 -36
- package/src/imageconfig.js +0 -5
- package/src/imageinline.js +0 -44
- package/src/imageinsert/imageinsertui.js +0 -216
- package/src/imageinsert/imageinsertviaurlui.js +0 -175
- package/src/imageinsert/ui/imageinsertformview.js +0 -117
- package/src/imageinsert/ui/imageinserturlview.js +0 -102
- package/src/imageinsert.js +0 -43
- package/src/imageinsertviaurl.js +0 -41
- package/src/imageresize/imagecustomresizeui.js +0 -177
- package/src/imageresize/imageresizebuttons.js +0 -303
- package/src/imageresize/imageresizeediting.js +0 -206
- package/src/imageresize/imageresizehandles.js +0 -118
- package/src/imageresize/resizeimagecommand.js +0 -63
- package/src/imageresize/ui/imagecustomresizeformview.js +0 -264
- package/src/imageresize/utils/getselectedimageeditornodes.js +0 -25
- package/src/imageresize/utils/getselectedimagepossibleresizerange.js +0 -33
- package/src/imageresize/utils/getselectedimagewidthinunits.js +0 -42
- package/src/imageresize/utils/tryparsedimensionwithunit.js +0 -58
- package/src/imageresize.js +0 -38
- package/src/imagesizeattributes.js +0 -163
- package/src/imagestyle/converters.js +0 -118
- package/src/imagestyle/imagestylecommand.js +0 -117
- package/src/imagestyle/imagestyleediting.js +0 -127
- package/src/imagestyle/imagestyleui.js +0 -198
- package/src/imagestyle/utils.js +0 -333
- package/src/imagestyle.js +0 -42
- package/src/imagetextalternative/imagetextalternativecommand.js +0 -44
- package/src/imagetextalternative/imagetextalternativeediting.js +0 -41
- package/src/imagetextalternative/imagetextalternativeui.js +0 -183
- package/src/imagetextalternative/ui/textalternativeformview.js +0 -193
- package/src/imagetextalternative.js +0 -39
- package/src/imagetoolbar.js +0 -63
- package/src/imageupload/imageuploadediting.js +0 -482
- package/src/imageupload/imageuploadprogress.js +0 -222
- package/src/imageupload/imageuploadui.js +0 -135
- package/src/imageupload/uploadimagecommand.js +0 -110
- package/src/imageupload/utils.js +0 -114
- package/src/imageupload.js +0 -42
- package/src/imageutils.js +0 -309
- package/src/index.js +0 -67
- package/src/pictureediting.js +0 -136
- package/theme/image.css +0 -143
- package/theme/imagecaption.css +0 -53
- package/theme/imagecustomresizeform.css +0 -4
- package/theme/imageinsert.css +0 -14
- package/theme/imageplaceholder.css +0 -10
- package/theme/imageresize.css +0 -53
- package/theme/imagestyle.css +0 -120
- package/theme/imageuploadicon.css +0 -23
- package/theme/imageuploadloader.css +0 -18
- package/theme/imageuploadprogress.css +0 -19
- package/theme/textalternativeform.css +0 -4
- /package/{src → dist}/augmentation.d.ts +0 -0
- /package/{src → dist}/imageresize/utils/tryparsedimensionwithunit.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module image/image/insertimagecommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { logWarning, toArray } from 'ckeditor5/src/utils.js';
|
|
10
|
-
/**
|
|
11
|
-
* Insert image command.
|
|
12
|
-
*
|
|
13
|
-
* The command is registered by the {@link module:image/image/imageediting~ImageEditing} plugin as `insertImage`
|
|
14
|
-
* and it is also available via aliased `imageInsert` name.
|
|
15
|
-
*
|
|
16
|
-
* In order to insert an image at the current selection position
|
|
17
|
-
* (according to the {@link module:widget/utils~findOptimalInsertionRange} algorithm),
|
|
18
|
-
* execute the command and specify the image source:
|
|
19
|
-
*
|
|
20
|
-
* ```ts
|
|
21
|
-
* editor.execute( 'insertImage', { source: 'http://url.to.the/image' } );
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* It is also possible to insert multiple images at once:
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* editor.execute( 'insertImage', {
|
|
28
|
-
* source: [
|
|
29
|
-
* 'path/to/image.jpg',
|
|
30
|
-
* 'path/to/other-image.jpg'
|
|
31
|
-
* ]
|
|
32
|
-
* } );
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* If you want to take the full control over the process, you can specify individual model attributes:
|
|
36
|
-
*
|
|
37
|
-
* ```ts
|
|
38
|
-
* editor.execute( 'insertImage', {
|
|
39
|
-
* source: [
|
|
40
|
-
* { src: 'path/to/image.jpg', alt: 'First alt text' },
|
|
41
|
-
* { src: 'path/to/other-image.jpg', alt: 'Second alt text', customAttribute: 'My attribute value' }
|
|
42
|
-
* ]
|
|
43
|
-
* } );
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export class InsertImageCommand extends Command {
|
|
47
|
-
/**
|
|
48
|
-
* @inheritDoc
|
|
49
|
-
*/
|
|
50
|
-
constructor(editor) {
|
|
51
|
-
super(editor);
|
|
52
|
-
const configImageInsertType = editor.config.get('image.insert.type');
|
|
53
|
-
if (!editor.plugins.has('ImageBlockEditing')) {
|
|
54
|
-
if (configImageInsertType === 'block') {
|
|
55
|
-
/**
|
|
56
|
-
* The {@link module:image/imageblock~ImageBlock} plugin must be enabled to allow inserting block images. See
|
|
57
|
-
* {@link module:image/imageconfig~ImageInsertConfig#type} to learn more.
|
|
58
|
-
*
|
|
59
|
-
* @error image-block-plugin-required
|
|
60
|
-
*/
|
|
61
|
-
logWarning('image-block-plugin-required');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (!editor.plugins.has('ImageInlineEditing')) {
|
|
65
|
-
if (configImageInsertType === 'inline') {
|
|
66
|
-
/**
|
|
67
|
-
* The {@link module:image/imageinline~ImageInline} plugin must be enabled to allow inserting inline images. See
|
|
68
|
-
* {@link module:image/imageconfig~ImageInsertConfig#type} to learn more.
|
|
69
|
-
*
|
|
70
|
-
* @error image-inline-plugin-required
|
|
71
|
-
*/
|
|
72
|
-
logWarning('image-inline-plugin-required');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @inheritDoc
|
|
78
|
-
*/
|
|
79
|
-
refresh() {
|
|
80
|
-
const imageUtils = this.editor.plugins.get('ImageUtils');
|
|
81
|
-
this.isEnabled = imageUtils.isImageAllowed();
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Executes the command.
|
|
85
|
-
*
|
|
86
|
-
* @fires execute
|
|
87
|
-
* @param options Options for the executed command.
|
|
88
|
-
* @param options.imageType The type of the image to insert. If not specified, the type will be determined automatically.
|
|
89
|
-
* @param options.source The image source or an array of image sources to insert.
|
|
90
|
-
* @param options.breakBlock If set to `true`, the block at the selection start will be broken before inserting the image.
|
|
91
|
-
* See the documentation of the command to learn more about accepted formats.
|
|
92
|
-
*/
|
|
93
|
-
execute(options) {
|
|
94
|
-
const sourceDefinitions = toArray(options.source);
|
|
95
|
-
const selection = this.editor.model.document.selection;
|
|
96
|
-
const imageUtils = this.editor.plugins.get('ImageUtils');
|
|
97
|
-
// In case of multiple images, each image (starting from the 2nd) will be inserted at a position that
|
|
98
|
-
// follows the previous one. That will move the selection and, to stay on the safe side and make sure
|
|
99
|
-
// all images inherit the same selection attributes, they are collected beforehand.
|
|
100
|
-
//
|
|
101
|
-
// Applying these attributes ensures, for instance, that inserting an (inline) image into a link does
|
|
102
|
-
// not split that link but preserves its continuity.
|
|
103
|
-
//
|
|
104
|
-
// Note: Selection attributes that do not make sense for images will be filtered out by insertImage() anyway.
|
|
105
|
-
const selectionAttributes = Object.fromEntries(selection.getAttributes());
|
|
106
|
-
sourceDefinitions.forEach((sourceDefinition, index) => {
|
|
107
|
-
const selectedElement = selection.getSelectedElement();
|
|
108
|
-
if (typeof sourceDefinition === 'string') {
|
|
109
|
-
sourceDefinition = { src: sourceDefinition };
|
|
110
|
-
}
|
|
111
|
-
// Inserting of an inline image replace the selected element and make a selection on the inserted image.
|
|
112
|
-
// Therefore inserting multiple inline images requires creating position after each element.
|
|
113
|
-
if (index && selectedElement && imageUtils.isImage(selectedElement)) {
|
|
114
|
-
const position = this.editor.model.createPositionAfter(selectedElement);
|
|
115
|
-
imageUtils.insertImage({ ...sourceDefinition, ...selectionAttributes }, position, options.imageType);
|
|
116
|
-
}
|
|
117
|
-
else if (options.breakBlock) {
|
|
118
|
-
imageUtils.insertImage({ ...sourceDefinition, ...selectionAttributes }, selection.getFirstPosition(), options.imageType);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
imageUtils.insertImage({ ...sourceDefinition, ...selectionAttributes }, null, options.imageType);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
import { Command } from 'ckeditor5/src/core.js';
|
|
6
|
-
/**
|
|
7
|
-
* @module image/image/replaceimagesourcecommand
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Replace image source command.
|
|
11
|
-
*
|
|
12
|
-
* Changes image source to the one provided. Can be executed as follows:
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* editor.execute( 'replaceImageSource', { source: 'http://url.to.the/image' } );
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export class ReplaceImageSourceCommand extends Command {
|
|
19
|
-
constructor(editor) {
|
|
20
|
-
super(editor);
|
|
21
|
-
this.decorate('cleanupImage');
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
refresh() {
|
|
27
|
-
const editor = this.editor;
|
|
28
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
29
|
-
const element = this.editor.model.document.selection.getSelectedElement();
|
|
30
|
-
this.isEnabled = imageUtils.isImage(element);
|
|
31
|
-
this.value = this.isEnabled ? element.getAttribute('src') : null;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Executes the command.
|
|
35
|
-
*
|
|
36
|
-
* @fires execute
|
|
37
|
-
* @param options Options for the executed command.
|
|
38
|
-
* @param options.source The image source to replace.
|
|
39
|
-
*/
|
|
40
|
-
execute(options) {
|
|
41
|
-
const image = this.editor.model.document.selection.getSelectedElement();
|
|
42
|
-
const imageUtils = this.editor.plugins.get('ImageUtils');
|
|
43
|
-
this.editor.model.change(writer => {
|
|
44
|
-
writer.setAttribute('src', options.source, image);
|
|
45
|
-
this.cleanupImage(writer, image);
|
|
46
|
-
imageUtils.setImageNaturalSizeAttributes(image);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Cleanup image attributes that are not relevant to the new source.
|
|
51
|
-
*
|
|
52
|
-
* Removed attributes are: 'srcset', 'sizes', 'sources', 'width', 'height', 'alt'.
|
|
53
|
-
*
|
|
54
|
-
* This method is decorated, to allow custom cleanup logic.
|
|
55
|
-
* For example, to remove 'myImageId' attribute after 'src' has changed:
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* replaceImageSourceCommand.on( 'cleanupImage', ( eventInfo, [ writer, image ] ) => {
|
|
59
|
-
* writer.removeAttribute( 'myImageId', image );
|
|
60
|
-
* } );
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
cleanupImage(writer, image) {
|
|
64
|
-
writer.removeAttribute('srcset', image);
|
|
65
|
-
writer.removeAttribute('sizes', image);
|
|
66
|
-
/**
|
|
67
|
-
* In case responsive images some attributes should be cleaned up.
|
|
68
|
-
* Check: https://github.com/ckeditor/ckeditor5/issues/15093
|
|
69
|
-
*/
|
|
70
|
-
writer.removeAttribute('sources', image);
|
|
71
|
-
writer.removeAttribute('width', image);
|
|
72
|
-
writer.removeAttribute('height', image);
|
|
73
|
-
writer.removeAttribute('alt', image);
|
|
74
|
-
}
|
|
75
|
-
}
|
package/src/image/ui/utils.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
import { BalloonPanelView } from 'ckeditor5/src/ui.js';
|
|
6
|
-
/**
|
|
7
|
-
* A helper utility that positions the
|
|
8
|
-
* {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
|
|
9
|
-
* with respect to the image in the editor content, if one is selected.
|
|
10
|
-
*
|
|
11
|
-
* @param editor The editor instance.
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export function repositionContextualBalloon(editor) {
|
|
15
|
-
const balloon = editor.plugins.get('ContextualBalloon');
|
|
16
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
17
|
-
if (imageUtils.getClosestSelectedImageWidget(editor.editing.view.document.selection)) {
|
|
18
|
-
const position = getBalloonPositionData(editor);
|
|
19
|
-
balloon.updatePosition(position);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Returns the positioning options that control the geometry of the
|
|
24
|
-
* {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
|
|
25
|
-
* to the selected element in the editor content.
|
|
26
|
-
*
|
|
27
|
-
* @param editor The editor instance.
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export function getBalloonPositionData(editor) {
|
|
31
|
-
const editingView = editor.editing.view;
|
|
32
|
-
const defaultPositions = BalloonPanelView.defaultPositions;
|
|
33
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
34
|
-
return {
|
|
35
|
-
target: editingView.domConverter.mapViewToDom(imageUtils.getClosestSelectedImageWidget(editingView.document.selection)),
|
|
36
|
-
positions: [
|
|
37
|
-
defaultPositions.northArrowSouth,
|
|
38
|
-
defaultPositions.northArrowSouthWest,
|
|
39
|
-
defaultPositions.northArrowSouthEast,
|
|
40
|
-
defaultPositions.southArrowNorth,
|
|
41
|
-
defaultPositions.southArrowNorthWest,
|
|
42
|
-
defaultPositions.southArrowNorthEast,
|
|
43
|
-
defaultPositions.viewportStickyNorth
|
|
44
|
-
]
|
|
45
|
-
};
|
|
46
|
-
}
|
package/src/image/utils.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
import { first } from 'ckeditor5/src/utils.js';
|
|
6
|
-
/**
|
|
7
|
-
* Creates a view element representing the inline image.
|
|
8
|
-
*
|
|
9
|
-
* ```html
|
|
10
|
-
* <span class="image-inline"><img></img></span>
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Note that `alt` and `src` attributes are converted separately, so they are not included.
|
|
14
|
-
*
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export function createInlineImageViewElement(writer) {
|
|
18
|
-
return writer.createContainerElement('span', { class: 'image-inline' }, writer.createEmptyElement('img'));
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Creates a view element representing the block image.
|
|
22
|
-
*
|
|
23
|
-
* ```html
|
|
24
|
-
* <figure class="image"><img></img></figure>
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* Note that `alt` and `src` attributes are converted separately, so they are not included.
|
|
28
|
-
*
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
export function createBlockImageViewElement(writer) {
|
|
32
|
-
return writer.createContainerElement('figure', { class: 'image' }, [
|
|
33
|
-
writer.createEmptyElement('img'),
|
|
34
|
-
writer.createSlot('children')
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* A function returning a `MatcherPattern` for a particular type of View images.
|
|
39
|
-
*
|
|
40
|
-
* @internal
|
|
41
|
-
* @param matchImageType The type of created image.
|
|
42
|
-
*/
|
|
43
|
-
export function getImgViewElementMatcher(editor, matchImageType) {
|
|
44
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
45
|
-
const areBothImagePluginsLoaded = editor.plugins.has('ImageInlineEditing') && editor.plugins.has('ImageBlockEditing');
|
|
46
|
-
return element => {
|
|
47
|
-
// Check if the matched view element is an <img>.
|
|
48
|
-
if (!imageUtils.isInlineImageView(element)) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
// If just one of the plugins is loaded (block or inline), it will match all kinds of images.
|
|
52
|
-
if (!areBothImagePluginsLoaded) {
|
|
53
|
-
return getPositiveMatchPattern(element);
|
|
54
|
-
}
|
|
55
|
-
// The <img> can be standalone, wrapped in <figure>...</figure> (ImageBlock plugin) or
|
|
56
|
-
// wrapped in <figure><a>...</a></figure> (LinkImage plugin).
|
|
57
|
-
const imageType = element.getStyle('display') == 'block' || element.findAncestor(imageUtils.isBlockImageView) ?
|
|
58
|
-
'imageBlock' :
|
|
59
|
-
'imageInline';
|
|
60
|
-
if (imageType !== matchImageType) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
return getPositiveMatchPattern(element);
|
|
64
|
-
};
|
|
65
|
-
function getPositiveMatchPattern(element) {
|
|
66
|
-
const pattern = {
|
|
67
|
-
name: true
|
|
68
|
-
};
|
|
69
|
-
// This will trigger src consumption (See https://github.com/ckeditor/ckeditor5/issues/11530).
|
|
70
|
-
if (element.hasAttribute('src')) {
|
|
71
|
-
pattern.attributes = ['src'];
|
|
72
|
-
}
|
|
73
|
-
return pattern;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Considering the current model selection, it returns the name of the model image element
|
|
78
|
-
* (`'imageBlock'` or `'imageInline'`) that will make most sense from the UX perspective if a new
|
|
79
|
-
* image was inserted (also: uploaded, dropped, pasted) at that selection.
|
|
80
|
-
*
|
|
81
|
-
* The assumption is that inserting images into empty blocks or on other block widgets should
|
|
82
|
-
* produce block images. Inline images should be inserted in other cases, e.g. in paragraphs
|
|
83
|
-
* that already contain some text.
|
|
84
|
-
*
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
export function determineImageTypeForInsertionAtSelection(schema, selection) {
|
|
88
|
-
const firstBlock = first(selection.getSelectedBlocks());
|
|
89
|
-
// Insert a block image if the selection is not in/on block elements or it's on a block widget.
|
|
90
|
-
if (!firstBlock || schema.isObject(firstBlock)) {
|
|
91
|
-
return 'imageBlock';
|
|
92
|
-
}
|
|
93
|
-
// A block image should also be inserted into an empty block element
|
|
94
|
-
// (that is not an empty list item so the list won't get split).
|
|
95
|
-
if (firstBlock.isEmpty && firstBlock.name != 'listItem') {
|
|
96
|
-
return 'imageBlock';
|
|
97
|
-
}
|
|
98
|
-
// Otherwise insert an inline image.
|
|
99
|
-
return 'imageInline';
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Returns parsed value of the size, but only if it contains unit: px.
|
|
103
|
-
*
|
|
104
|
-
* @internal
|
|
105
|
-
*/
|
|
106
|
-
export function getSizeValueIfInPx(size) {
|
|
107
|
-
if (size && size.endsWith('px')) {
|
|
108
|
-
return parseInt(size);
|
|
109
|
-
}
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Returns true if both styles (width and height) are set.
|
|
114
|
-
*
|
|
115
|
-
* If both image styles: width & height are set, they will override the image width & height attributes in the
|
|
116
|
-
* browser. In this case, the image looks the same as if these styles were applied to attributes instead of styles.
|
|
117
|
-
* That's why we can upcast these styles to width & height attributes instead of resizedWidth and resizedHeight.
|
|
118
|
-
*
|
|
119
|
-
* @internal
|
|
120
|
-
*/
|
|
121
|
-
export function widthAndHeightStylesAreBothSet(viewElement) {
|
|
122
|
-
const widthStyle = getSizeValueIfInPx(viewElement.getStyle('width'));
|
|
123
|
-
const heightStyle = getSizeValueIfInPx(viewElement.getStyle('height'));
|
|
124
|
-
return !!(widthStyle && heightStyle);
|
|
125
|
-
}
|
package/src/image.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module image/image
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { ImageBlock } from './imageblock.js';
|
|
10
|
-
import { ImageInline } from './imageinline.js';
|
|
11
|
-
import '../theme/image.css';
|
|
12
|
-
/**
|
|
13
|
-
* The image plugin.
|
|
14
|
-
*
|
|
15
|
-
* For a detailed overview, check the {@glink features/images/images-overview image feature} documentation.
|
|
16
|
-
*
|
|
17
|
-
* This is a "glue" plugin which loads the following plugins:
|
|
18
|
-
*
|
|
19
|
-
* * {@link module:image/imageblock~ImageBlock},
|
|
20
|
-
* * {@link module:image/imageinline~ImageInline},
|
|
21
|
-
*
|
|
22
|
-
* Usually, it is used in conjunction with other plugins from this package. See the {@glink api/image package page}
|
|
23
|
-
* for more information.
|
|
24
|
-
*/
|
|
25
|
-
export class Image extends Plugin {
|
|
26
|
-
/**
|
|
27
|
-
* @inheritDoc
|
|
28
|
-
*/
|
|
29
|
-
static get requires() {
|
|
30
|
-
return [ImageBlock, ImageInline];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
static get pluginName() {
|
|
36
|
-
return 'Image';
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @inheritDoc
|
|
40
|
-
*/
|
|
41
|
-
static get isOfficialPlugin() {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src/imageblock.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module image/imageblock
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { Widget } from 'ckeditor5/src/widget.js';
|
|
10
|
-
import { ImageTextAlternative } from './imagetextalternative.js';
|
|
11
|
-
import { ImageBlockEditing } from './image/imageblockediting.js';
|
|
12
|
-
import { ImageInsertUI } from './imageinsert/imageinsertui.js';
|
|
13
|
-
import '../theme/image.css';
|
|
14
|
-
/**
|
|
15
|
-
* The image block plugin.
|
|
16
|
-
*
|
|
17
|
-
* This is a "glue" plugin which loads the following plugins:
|
|
18
|
-
*
|
|
19
|
-
* * {@link module:image/image/imageblockediting~ImageBlockEditing},
|
|
20
|
-
* * {@link module:image/imagetextalternative~ImageTextAlternative}.
|
|
21
|
-
*
|
|
22
|
-
* Usually, it is used in conjunction with other plugins from this package. See the {@glink api/image package page}
|
|
23
|
-
* for more information.
|
|
24
|
-
*/
|
|
25
|
-
export class ImageBlock extends Plugin {
|
|
26
|
-
/**
|
|
27
|
-
* @inheritDoc
|
|
28
|
-
*/
|
|
29
|
-
static get requires() {
|
|
30
|
-
return [ImageBlockEditing, Widget, ImageTextAlternative, ImageInsertUI];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
static get pluginName() {
|
|
36
|
-
return 'ImageBlock';
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @inheritDoc
|
|
40
|
-
*/
|
|
41
|
-
static get isOfficialPlugin() {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
}
|