@ckeditor/ckeditor5-image 39.0.2 → 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/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/pt-br.po +1 -1
- package/package.json +3 -3
- 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,56 +1,59 @@
|
|
|
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/image/imageinlineediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
|
|
10
|
-
import ImageEditing from './imageediting';
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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
|
-
|
|
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/image/imageinlineediting
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
|
|
10
|
+
import ImageEditing from './imageediting';
|
|
11
|
+
import ImageSizeAttributes from '../imagesizeattributes';
|
|
12
|
+
import ImageUtils from '../imageutils';
|
|
13
|
+
/**
|
|
14
|
+
* The image inline plugin.
|
|
15
|
+
*
|
|
16
|
+
* It registers:
|
|
17
|
+
*
|
|
18
|
+
* * `<imageInline>` as an inline element in the document schema, and allows `alt`, `src` and `srcset` attributes.
|
|
19
|
+
* * converters for editing and data pipelines.
|
|
20
|
+
* * {@link module:image/image/imagetypecommand~ImageTypeCommand `'imageTypeInline'`} command that converts block images into
|
|
21
|
+
* inline images.
|
|
22
|
+
*/
|
|
23
|
+
export default class ImageInlineEditing extends Plugin {
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
static get requires(): readonly [typeof ImageEditing, typeof ImageSizeAttributes, typeof ImageUtils, typeof ClipboardPipeline];
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
static get pluginName(): "ImageInlineEditing";
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
init(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Configures conversion pipelines to support upcasting and downcasting
|
|
38
|
+
* inline images (inline image widgets) and their attributes.
|
|
39
|
+
*/
|
|
40
|
+
private _setupConversion;
|
|
41
|
+
/**
|
|
42
|
+
* Integrates the plugin with the clipboard pipeline.
|
|
43
|
+
*
|
|
44
|
+
* Idea is that the feature should recognize the user's intent when an **block** image is
|
|
45
|
+
* pasted or dropped. If such an image is pasted/dropped into a non-empty block
|
|
46
|
+
* (e.g. a paragraph with some text) it gets converted into an inline image on the fly.
|
|
47
|
+
*
|
|
48
|
+
* We assume this is the user's intent if they decided to put their image there.
|
|
49
|
+
*
|
|
50
|
+
* **Note**: If a block image has a caption, it will not be converted to an inline image
|
|
51
|
+
* to avoid the confusion. Captions are added on purpose and they should never be lost
|
|
52
|
+
* in the clipboard pipeline.
|
|
53
|
+
*
|
|
54
|
+
* See the `ImageBlockEditing` for the similar integration that works in the opposite direction.
|
|
55
|
+
*
|
|
56
|
+
* The feature also sets image `width` and `height` attributes when pasting.
|
|
57
|
+
*/
|
|
58
|
+
private _setupClipboardIntegration;
|
|
59
|
+
}
|
|
@@ -1,160 +1,176 @@
|
|
|
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/image/imageinlineediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
|
|
10
|
-
import { UpcastWriter } from 'ckeditor5/src/engine';
|
|
11
|
-
import { downcastImageAttribute, downcastSrcsetAttribute } from './converters';
|
|
12
|
-
import ImageEditing from './imageediting';
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
.add(downcastImageAttribute(imageUtils, 'imageInline', '
|
|
86
|
-
.add(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return blockViewImage;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
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/image/imageinlineediting
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
|
|
10
|
+
import { UpcastWriter } from 'ckeditor5/src/engine';
|
|
11
|
+
import { downcastImageAttribute, downcastSrcsetAttribute } from './converters';
|
|
12
|
+
import ImageEditing from './imageediting';
|
|
13
|
+
import ImageSizeAttributes from '../imagesizeattributes';
|
|
14
|
+
import ImageTypeCommand from './imagetypecommand';
|
|
15
|
+
import ImageUtils from '../imageutils';
|
|
16
|
+
import { getImgViewElementMatcher, createInlineImageViewElement, determineImageTypeForInsertionAtSelection } from '../image/utils';
|
|
17
|
+
/**
|
|
18
|
+
* The image inline plugin.
|
|
19
|
+
*
|
|
20
|
+
* It registers:
|
|
21
|
+
*
|
|
22
|
+
* * `<imageInline>` as an inline element in the document schema, and allows `alt`, `src` and `srcset` attributes.
|
|
23
|
+
* * converters for editing and data pipelines.
|
|
24
|
+
* * {@link module:image/image/imagetypecommand~ImageTypeCommand `'imageTypeInline'`} command that converts block images into
|
|
25
|
+
* inline images.
|
|
26
|
+
*/
|
|
27
|
+
export default class ImageInlineEditing extends Plugin {
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
static get requires() {
|
|
32
|
+
return [ImageEditing, ImageSizeAttributes, ImageUtils, ClipboardPipeline];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @inheritDoc
|
|
36
|
+
*/
|
|
37
|
+
static get pluginName() {
|
|
38
|
+
return 'ImageInlineEditing';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @inheritDoc
|
|
42
|
+
*/
|
|
43
|
+
init() {
|
|
44
|
+
const editor = this.editor;
|
|
45
|
+
const schema = editor.model.schema;
|
|
46
|
+
// Converters 'alt' and 'srcset' are added in 'ImageEditing' plugin.
|
|
47
|
+
schema.register('imageInline', {
|
|
48
|
+
inheritAllFrom: '$inlineObject',
|
|
49
|
+
allowAttributes: ['alt', 'src', 'srcset']
|
|
50
|
+
});
|
|
51
|
+
// Disallow inline images in captions (for now). This is the best spot to do that because
|
|
52
|
+
// independent packages can introduce captions (ImageCaption, TableCaption, etc.) so better this
|
|
53
|
+
// be future-proof.
|
|
54
|
+
schema.addChildCheck((context, childDefinition) => {
|
|
55
|
+
if (context.endsWith('caption') && childDefinition.name === 'imageInline') {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
this._setupConversion();
|
|
60
|
+
if (editor.plugins.has('ImageBlockEditing')) {
|
|
61
|
+
editor.commands.add('imageTypeInline', new ImageTypeCommand(this.editor, 'imageInline'));
|
|
62
|
+
this._setupClipboardIntegration();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Configures conversion pipelines to support upcasting and downcasting
|
|
67
|
+
* inline images (inline image widgets) and their attributes.
|
|
68
|
+
*/
|
|
69
|
+
_setupConversion() {
|
|
70
|
+
const editor = this.editor;
|
|
71
|
+
const t = editor.t;
|
|
72
|
+
const conversion = editor.conversion;
|
|
73
|
+
const imageUtils = editor.plugins.get('ImageUtils');
|
|
74
|
+
conversion.for('dataDowncast')
|
|
75
|
+
.elementToElement({
|
|
76
|
+
model: 'imageInline',
|
|
77
|
+
view: (modelElement, { writer }) => writer.createEmptyElement('img')
|
|
78
|
+
});
|
|
79
|
+
conversion.for('editingDowncast')
|
|
80
|
+
.elementToStructure({
|
|
81
|
+
model: 'imageInline',
|
|
82
|
+
view: (modelElement, { writer }) => imageUtils.toImageWidget(createInlineImageViewElement(writer), writer, t('image widget'))
|
|
83
|
+
});
|
|
84
|
+
conversion.for('downcast')
|
|
85
|
+
.add(downcastImageAttribute(imageUtils, 'imageInline', 'src'))
|
|
86
|
+
.add(downcastImageAttribute(imageUtils, 'imageInline', 'alt'))
|
|
87
|
+
.add(downcastSrcsetAttribute(imageUtils, 'imageInline'));
|
|
88
|
+
// More image related upcasts are in 'ImageEditing' plugin.
|
|
89
|
+
conversion.for('upcast')
|
|
90
|
+
.elementToElement({
|
|
91
|
+
view: getImgViewElementMatcher(editor, 'imageInline'),
|
|
92
|
+
model: (viewImage, { writer }) => writer.createElement('imageInline', viewImage.hasAttribute('src') ? { src: viewImage.getAttribute('src') } : undefined)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Integrates the plugin with the clipboard pipeline.
|
|
97
|
+
*
|
|
98
|
+
* Idea is that the feature should recognize the user's intent when an **block** image is
|
|
99
|
+
* pasted or dropped. If such an image is pasted/dropped into a non-empty block
|
|
100
|
+
* (e.g. a paragraph with some text) it gets converted into an inline image on the fly.
|
|
101
|
+
*
|
|
102
|
+
* We assume this is the user's intent if they decided to put their image there.
|
|
103
|
+
*
|
|
104
|
+
* **Note**: If a block image has a caption, it will not be converted to an inline image
|
|
105
|
+
* to avoid the confusion. Captions are added on purpose and they should never be lost
|
|
106
|
+
* in the clipboard pipeline.
|
|
107
|
+
*
|
|
108
|
+
* See the `ImageBlockEditing` for the similar integration that works in the opposite direction.
|
|
109
|
+
*
|
|
110
|
+
* The feature also sets image `width` and `height` attributes when pasting.
|
|
111
|
+
*/
|
|
112
|
+
_setupClipboardIntegration() {
|
|
113
|
+
const editor = this.editor;
|
|
114
|
+
const model = editor.model;
|
|
115
|
+
const editingView = editor.editing.view;
|
|
116
|
+
const imageUtils = editor.plugins.get('ImageUtils');
|
|
117
|
+
const clipboardPipeline = editor.plugins.get('ClipboardPipeline');
|
|
118
|
+
this.listenTo(clipboardPipeline, 'inputTransformation', (evt, data) => {
|
|
119
|
+
const docFragmentChildren = Array.from(data.content.getChildren());
|
|
120
|
+
let modelRange;
|
|
121
|
+
// Make sure only <figure class="image"></figure> elements are dropped or pasted. Otherwise, if there some other HTML
|
|
122
|
+
// mixed up, this should be handled as a regular paste.
|
|
123
|
+
if (!docFragmentChildren.every(imageUtils.isBlockImageView)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
// When drag and dropping, data.targetRanges specifies where to drop because
|
|
127
|
+
// this is usually a different place than the current model selection (the user
|
|
128
|
+
// uses a drop marker to specify the drop location).
|
|
129
|
+
if (data.targetRanges) {
|
|
130
|
+
modelRange = editor.editing.mapper.toModelRange(data.targetRanges[0]);
|
|
131
|
+
}
|
|
132
|
+
// Pasting, however, always occurs at the current model selection.
|
|
133
|
+
else {
|
|
134
|
+
modelRange = model.document.selection.getFirstRange();
|
|
135
|
+
}
|
|
136
|
+
const selection = model.createSelection(modelRange);
|
|
137
|
+
// Convert block images into inline images only when pasting or dropping into non-empty blocks
|
|
138
|
+
// and when the block is not an object (e.g. pasting to replace another widget).
|
|
139
|
+
if (determineImageTypeForInsertionAtSelection(model.schema, selection) === 'imageInline') {
|
|
140
|
+
const writer = new UpcastWriter(editingView.document);
|
|
141
|
+
// Unwrap <figure class="image"><img .../></figure> -> <img ... />
|
|
142
|
+
// but <figure class="image"><img .../><figcaption>...</figcaption></figure> -> stays the same
|
|
143
|
+
const inlineViewImages = docFragmentChildren.map(blockViewImage => {
|
|
144
|
+
// If there's just one child, it can be either <img /> or <a><img></a>.
|
|
145
|
+
// If there are other children than <img>, this means that the block image
|
|
146
|
+
// has a caption or some other features and this kind of image should be
|
|
147
|
+
// pasted/dropped without modifications.
|
|
148
|
+
if (blockViewImage.childCount === 1) {
|
|
149
|
+
// Pass the attributes which are present only in the <figure> to the <img>
|
|
150
|
+
// (e.g. the style="width:10%" attribute applied by the ImageResize plugin).
|
|
151
|
+
Array.from(blockViewImage.getAttributes())
|
|
152
|
+
.forEach(attribute => writer.setAttribute(...attribute, imageUtils.findViewImgElement(blockViewImage)));
|
|
153
|
+
return blockViewImage.getChild(0);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
return blockViewImage;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
data.content = writer.createDocumentFragment(inlineViewImages);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
this.listenTo(clipboardPipeline, 'contentInsertion', (evt, data) => {
|
|
163
|
+
if (data.method !== 'paste') {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
model.change(writer => {
|
|
167
|
+
const range = writer.createRangeIn(data.content);
|
|
168
|
+
for (const item of range.getItems()) {
|
|
169
|
+
if (item.is('element', 'imageInline')) {
|
|
170
|
+
imageUtils.setImageNaturalSizeAttributes(item);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -1,48 +1,48 @@
|
|
|
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/image/imageloadobserver
|
|
7
|
-
*/
|
|
8
|
-
import { Observer } from 'ckeditor5/src/engine';
|
|
9
|
-
/**
|
|
10
|
-
* Observes all new images added to the {@link module:engine/view/document~Document},
|
|
11
|
-
* fires {@link module:engine/view/document~Document#event:imageLoaded} and
|
|
12
|
-
* {@link module:engine/view/document~Document#event:layoutChanged} event every time when the new image
|
|
13
|
-
* has been loaded.
|
|
14
|
-
*
|
|
15
|
-
* **Note:** This event is not fired for images that has been added to the document and rendered as `complete` (already loaded).
|
|
16
|
-
*/
|
|
17
|
-
export default class ImageLoadObserver extends Observer {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
observe(domRoot: HTMLElement): void;
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
stopObserving(domRoot: HTMLElement): void;
|
|
26
|
-
/**
|
|
27
|
-
* Fires {@link module:engine/view/document~Document#event:layoutChanged} and
|
|
28
|
-
* {@link module:engine/view/document~Document#event:imageLoaded}
|
|
29
|
-
* if observer {@link #isEnabled is enabled}.
|
|
30
|
-
*
|
|
31
|
-
* @param domEvent The DOM event.
|
|
32
|
-
*/
|
|
33
|
-
private _fireEvents;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Fired when an <img/> DOM element has been loaded in the DOM root.
|
|
37
|
-
*
|
|
38
|
-
* Introduced by {@link module:image/image/imageloadobserver~ImageLoadObserver}.
|
|
39
|
-
*
|
|
40
|
-
* @see module:image/image/imageloadobserver~ImageLoadObserver
|
|
41
|
-
*
|
|
42
|
-
* @eventName module:engine/view/document~Document#imageLoaded
|
|
43
|
-
* @param data Event data.
|
|
44
|
-
*/
|
|
45
|
-
export type ImageLoadedEvent = {
|
|
46
|
-
name: 'imageLoaded';
|
|
47
|
-
args: [Event];
|
|
48
|
-
};
|
|
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/image/imageloadobserver
|
|
7
|
+
*/
|
|
8
|
+
import { Observer } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* Observes all new images added to the {@link module:engine/view/document~Document},
|
|
11
|
+
* fires {@link module:engine/view/document~Document#event:imageLoaded} and
|
|
12
|
+
* {@link module:engine/view/document~Document#event:layoutChanged} event every time when the new image
|
|
13
|
+
* has been loaded.
|
|
14
|
+
*
|
|
15
|
+
* **Note:** This event is not fired for images that has been added to the document and rendered as `complete` (already loaded).
|
|
16
|
+
*/
|
|
17
|
+
export default class ImageLoadObserver extends Observer {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
observe(domRoot: HTMLElement): void;
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
stopObserving(domRoot: HTMLElement): void;
|
|
26
|
+
/**
|
|
27
|
+
* Fires {@link module:engine/view/document~Document#event:layoutChanged} and
|
|
28
|
+
* {@link module:engine/view/document~Document#event:imageLoaded}
|
|
29
|
+
* if observer {@link #isEnabled is enabled}.
|
|
30
|
+
*
|
|
31
|
+
* @param domEvent The DOM event.
|
|
32
|
+
*/
|
|
33
|
+
private _fireEvents;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fired when an <img/> DOM element has been loaded in the DOM root.
|
|
37
|
+
*
|
|
38
|
+
* Introduced by {@link module:image/image/imageloadobserver~ImageLoadObserver}.
|
|
39
|
+
*
|
|
40
|
+
* @see module:image/image/imageloadobserver~ImageLoadObserver
|
|
41
|
+
*
|
|
42
|
+
* @eventName module:engine/view/document~Document#imageLoaded
|
|
43
|
+
* @param data Event data.
|
|
44
|
+
*/
|
|
45
|
+
export type ImageLoadedEvent = {
|
|
46
|
+
name: 'imageLoaded';
|
|
47
|
+
args: [Event];
|
|
48
|
+
};
|