@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.
Files changed (116) hide show
  1. package/build/image.js +1 -1
  2. package/build/image.js.map +1 -0
  3. package/build/translations/pt-br.js +1 -1
  4. package/ckeditor5-metadata.json +12 -0
  5. package/lang/translations/pt-br.po +1 -1
  6. package/package.json +3 -3
  7. package/src/augmentation.d.ts +56 -55
  8. package/src/augmentation.js +5 -5
  9. package/src/autoimage.d.ts +52 -52
  10. package/src/autoimage.js +132 -132
  11. package/src/image/converters.d.ts +66 -66
  12. package/src/image/converters.js +232 -242
  13. package/src/image/imageblockediting.d.ts +58 -55
  14. package/src/image/imageblockediting.js +152 -136
  15. package/src/image/imageediting.d.ts +30 -30
  16. package/src/image/imageediting.js +63 -74
  17. package/src/image/imageinlineediting.d.ts +59 -56
  18. package/src/image/imageinlineediting.js +176 -160
  19. package/src/image/imageloadobserver.d.ts +48 -48
  20. package/src/image/imageloadobserver.js +52 -52
  21. package/src/image/imagetypecommand.d.ts +44 -40
  22. package/src/image/imagetypecommand.js +80 -77
  23. package/src/image/insertimagecommand.d.ts +66 -66
  24. package/src/image/insertimagecommand.js +120 -120
  25. package/src/image/replaceimagesourcecommand.d.ts +34 -34
  26. package/src/image/replaceimagesourcecommand.js +44 -44
  27. package/src/image/ui/utils.d.ts +25 -25
  28. package/src/image/ui/utils.js +44 -44
  29. package/src/image/utils.d.ts +64 -52
  30. package/src/image/utils.js +121 -100
  31. package/src/image.d.ts +34 -34
  32. package/src/image.js +38 -38
  33. package/src/imageblock.d.ts +33 -33
  34. package/src/imageblock.js +37 -37
  35. package/src/imagecaption/imagecaptionediting.d.ts +89 -89
  36. package/src/imagecaption/imagecaptionediting.js +225 -225
  37. package/src/imagecaption/imagecaptionui.d.ts +26 -26
  38. package/src/imagecaption/imagecaptionui.js +61 -61
  39. package/src/imagecaption/imagecaptionutils.d.ts +38 -38
  40. package/src/imagecaption/imagecaptionutils.js +62 -62
  41. package/src/imagecaption/toggleimagecaptioncommand.d.ts +66 -66
  42. package/src/imagecaption/toggleimagecaptioncommand.js +138 -138
  43. package/src/imagecaption.d.ts +26 -26
  44. package/src/imagecaption.js +30 -30
  45. package/src/imageconfig.d.ts +713 -713
  46. package/src/imageconfig.js +5 -5
  47. package/src/imageinline.d.ts +33 -33
  48. package/src/imageinline.js +37 -37
  49. package/src/imageinsert/imageinsertui.d.ts +44 -44
  50. package/src/imageinsert/imageinsertui.js +141 -141
  51. package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -61
  52. package/src/imageinsert/ui/imageinsertformrowview.js +54 -54
  53. package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -106
  54. package/src/imageinsert/ui/imageinsertpanelview.js +161 -161
  55. package/src/imageinsert/utils.d.ts +25 -25
  56. package/src/imageinsert/utils.js +58 -58
  57. package/src/imageinsert.d.ts +33 -33
  58. package/src/imageinsert.js +37 -37
  59. package/src/imageinsertviaurl.d.ts +30 -30
  60. package/src/imageinsertviaurl.js +34 -34
  61. package/src/imageresize/imageresizebuttons.d.ts +67 -67
  62. package/src/imageresize/imageresizebuttons.js +217 -217
  63. package/src/imageresize/imageresizeediting.d.ts +37 -37
  64. package/src/imageresize/imageresizeediting.js +165 -114
  65. package/src/imageresize/imageresizehandles.d.ts +31 -30
  66. package/src/imageresize/imageresizehandles.js +114 -107
  67. package/src/imageresize/resizeimagecommand.d.ts +42 -42
  68. package/src/imageresize/resizeimagecommand.js +63 -61
  69. package/src/imageresize.d.ts +27 -27
  70. package/src/imageresize.js +31 -31
  71. package/src/imagesizeattributes.d.ts +34 -0
  72. package/src/imagesizeattributes.js +143 -0
  73. package/src/imagestyle/converters.d.ts +24 -24
  74. package/src/imagestyle/converters.js +79 -79
  75. package/src/imagestyle/imagestylecommand.d.ts +68 -65
  76. package/src/imagestyle/imagestylecommand.js +107 -101
  77. package/src/imagestyle/imagestyleediting.d.ts +50 -50
  78. package/src/imagestyle/imagestyleediting.js +108 -108
  79. package/src/imagestyle/imagestyleui.d.ts +56 -56
  80. package/src/imagestyle/imagestyleui.js +192 -192
  81. package/src/imagestyle/utils.d.ts +101 -101
  82. package/src/imagestyle/utils.js +329 -329
  83. package/src/imagestyle.d.ts +32 -32
  84. package/src/imagestyle.js +36 -36
  85. package/src/imagetextalternative/imagetextalternativecommand.d.ts +34 -34
  86. package/src/imagetextalternative/imagetextalternativecommand.js +44 -44
  87. package/src/imagetextalternative/imagetextalternativeediting.d.ts +28 -28
  88. package/src/imagetextalternative/imagetextalternativeediting.js +35 -35
  89. package/src/imagetextalternative/imagetextalternativeui.d.ts +68 -68
  90. package/src/imagetextalternative/imagetextalternativeui.js +173 -173
  91. package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -72
  92. package/src/imagetextalternative/ui/textalternativeformview.js +121 -121
  93. package/src/imagetextalternative.d.ts +29 -29
  94. package/src/imagetextalternative.js +33 -33
  95. package/src/imagetoolbar.d.ts +35 -35
  96. package/src/imagetoolbar.js +57 -57
  97. package/src/imageupload/imageuploadediting.d.ts +111 -111
  98. package/src/imageupload/imageuploadediting.js +337 -335
  99. package/src/imageupload/imageuploadprogress.d.ts +42 -42
  100. package/src/imageupload/imageuploadprogress.js +211 -211
  101. package/src/imageupload/imageuploadui.d.ts +23 -23
  102. package/src/imageupload/imageuploadui.js +57 -57
  103. package/src/imageupload/uploadimagecommand.d.ts +60 -60
  104. package/src/imageupload/uploadimagecommand.js +100 -100
  105. package/src/imageupload/utils.d.ts +33 -33
  106. package/src/imageupload/utils.js +112 -112
  107. package/src/imageupload.d.ts +32 -32
  108. package/src/imageupload.js +36 -36
  109. package/src/imageutils.d.ts +125 -102
  110. package/src/imageutils.js +306 -248
  111. package/src/index.d.ts +48 -47
  112. package/src/index.js +39 -38
  113. package/src/pictureediting.d.ts +88 -88
  114. package/src/pictureediting.js +130 -130
  115. package/theme/image.css +38 -11
  116. 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 ImageUtils from '../imageutils';
12
- /**
13
- * The image inline plugin.
14
- *
15
- * It registers:
16
- *
17
- * * `<imageInline>` as an inline element in the document schema, and allows `alt`, `src` and `srcset` attributes.
18
- * * converters for editing and data pipelines.
19
- * * {@link module:image/image/imagetypecommand~ImageTypeCommand `'imageTypeInline'`} command that converts block images into
20
- * inline images.
21
- */
22
- export default class ImageInlineEditing extends Plugin {
23
- /**
24
- * @inheritDoc
25
- */
26
- static get requires(): readonly [typeof ImageEditing, typeof ImageUtils, typeof ClipboardPipeline];
27
- /**
28
- * @inheritDoc
29
- */
30
- static get pluginName(): "ImageInlineEditing";
31
- /**
32
- * @inheritDoc
33
- */
34
- init(): void;
35
- /**
36
- * Configures conversion pipelines to support upcasting and downcasting
37
- * inline images (inline image widgets) and their attributes.
38
- */
39
- private _setupConversion;
40
- /**
41
- * Integrates the plugin with the clipboard pipeline.
42
- *
43
- * Idea is that the feature should recognize the user's intent when an **block** image is
44
- * pasted or dropped. If such an image is pasted/dropped into a non-empty block
45
- * (e.g. a paragraph with some text) it gets converted into an inline image on the fly.
46
- *
47
- * We assume this is the user's intent if they decided to put their image there.
48
- *
49
- * **Note**: If a block image has a caption, it will not be converted to an inline image
50
- * to avoid the confusion. Captions are added on purpose and they should never be lost
51
- * in the clipboard pipeline.
52
- *
53
- * See the `ImageBlockEditing` for the similar integration that works in the opposite direction.
54
- */
55
- private _setupClipboardIntegration;
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 ImageTypeCommand from './imagetypecommand';
14
- import ImageUtils from '../imageutils';
15
- import { getImgViewElementMatcher, createInlineImageViewElement, determineImageTypeForInsertionAtSelection } from '../image/utils';
16
- /**
17
- * The image inline plugin.
18
- *
19
- * It registers:
20
- *
21
- * * `<imageInline>` as an inline element in the document schema, and allows `alt`, `src` and `srcset` attributes.
22
- * * converters for editing and data pipelines.
23
- * * {@link module:image/image/imagetypecommand~ImageTypeCommand `'imageTypeInline'`} command that converts block images into
24
- * inline images.
25
- */
26
- export default class ImageInlineEditing extends Plugin {
27
- /**
28
- * @inheritDoc
29
- */
30
- static get requires() {
31
- return [ImageEditing, ImageUtils, ClipboardPipeline];
32
- }
33
- /**
34
- * @inheritDoc
35
- */
36
- static get pluginName() {
37
- return 'ImageInlineEditing';
38
- }
39
- /**
40
- * @inheritDoc
41
- */
42
- init() {
43
- const editor = this.editor;
44
- const schema = editor.model.schema;
45
- // Converters 'alt' and 'srcset' are added in 'ImageEditing' plugin.
46
- schema.register('imageInline', {
47
- inheritAllFrom: '$inlineObject',
48
- allowAttributes: ['alt', 'src', 'srcset']
49
- });
50
- // Disallow inline images in captions (for now). This is the best spot to do that because
51
- // independent packages can introduce captions (ImageCaption, TableCaption, etc.) so better this
52
- // be future-proof.
53
- schema.addChildCheck((context, childDefinition) => {
54
- if (context.endsWith('caption') && childDefinition.name === 'imageInline') {
55
- return false;
56
- }
57
- });
58
- this._setupConversion();
59
- if (editor.plugins.has('ImageBlockEditing')) {
60
- editor.commands.add('imageTypeInline', new ImageTypeCommand(this.editor, 'imageInline'));
61
- this._setupClipboardIntegration();
62
- }
63
- }
64
- /**
65
- * Configures conversion pipelines to support upcasting and downcasting
66
- * inline images (inline image widgets) and their attributes.
67
- */
68
- _setupConversion() {
69
- const editor = this.editor;
70
- const t = editor.t;
71
- const conversion = editor.conversion;
72
- const imageUtils = editor.plugins.get('ImageUtils');
73
- conversion.for('dataDowncast')
74
- .elementToElement({
75
- model: 'imageInline',
76
- view: (modelElement, { writer }) => writer.createEmptyElement('img')
77
- });
78
- conversion.for('editingDowncast')
79
- .elementToStructure({
80
- model: 'imageInline',
81
- view: (modelElement, { writer }) => imageUtils.toImageWidget(createInlineImageViewElement(writer), writer, t('image widget'))
82
- });
83
- conversion.for('downcast')
84
- .add(downcastImageAttribute(imageUtils, 'imageInline', 'src'))
85
- .add(downcastImageAttribute(imageUtils, 'imageInline', 'alt'))
86
- .add(downcastSrcsetAttribute(imageUtils, 'imageInline'));
87
- // More image related upcasts are in 'ImageEditing' plugin.
88
- conversion.for('upcast')
89
- .elementToElement({
90
- view: getImgViewElementMatcher(editor, 'imageInline'),
91
- model: (viewImage, { writer }) => writer.createElement('imageInline', viewImage.hasAttribute('src') ? { src: viewImage.getAttribute('src') } : undefined)
92
- });
93
- }
94
- /**
95
- * Integrates the plugin with the clipboard pipeline.
96
- *
97
- * Idea is that the feature should recognize the user's intent when an **block** image is
98
- * pasted or dropped. If such an image is pasted/dropped into a non-empty block
99
- * (e.g. a paragraph with some text) it gets converted into an inline image on the fly.
100
- *
101
- * We assume this is the user's intent if they decided to put their image there.
102
- *
103
- * **Note**: If a block image has a caption, it will not be converted to an inline image
104
- * to avoid the confusion. Captions are added on purpose and they should never be lost
105
- * in the clipboard pipeline.
106
- *
107
- * See the `ImageBlockEditing` for the similar integration that works in the opposite direction.
108
- */
109
- _setupClipboardIntegration() {
110
- const editor = this.editor;
111
- const model = editor.model;
112
- const editingView = editor.editing.view;
113
- const imageUtils = editor.plugins.get('ImageUtils');
114
- const clipboardPipeline = editor.plugins.get('ClipboardPipeline');
115
- this.listenTo(clipboardPipeline, 'inputTransformation', (evt, data) => {
116
- const docFragmentChildren = Array.from(data.content.getChildren());
117
- let modelRange;
118
- // Make sure only <figure class="image"></figure> elements are dropped or pasted. Otherwise, if there some other HTML
119
- // mixed up, this should be handled as a regular paste.
120
- if (!docFragmentChildren.every(imageUtils.isBlockImageView)) {
121
- return;
122
- }
123
- // When drag and dropping, data.targetRanges specifies where to drop because
124
- // this is usually a different place than the current model selection (the user
125
- // uses a drop marker to specify the drop location).
126
- if (data.targetRanges) {
127
- modelRange = editor.editing.mapper.toModelRange(data.targetRanges[0]);
128
- }
129
- // Pasting, however, always occurs at the current model selection.
130
- else {
131
- modelRange = model.document.selection.getFirstRange();
132
- }
133
- const selection = model.createSelection(modelRange);
134
- // Convert block images into inline images only when pasting or dropping into non-empty blocks
135
- // and when the block is not an object (e.g. pasting to replace another widget).
136
- if (determineImageTypeForInsertionAtSelection(model.schema, selection) === 'imageInline') {
137
- const writer = new UpcastWriter(editingView.document);
138
- // Unwrap <figure class="image"><img .../></figure> -> <img ... />
139
- // but <figure class="image"><img .../><figcaption>...</figcaption></figure> -> stays the same
140
- const inlineViewImages = docFragmentChildren.map(blockViewImage => {
141
- // If there's just one child, it can be either <img /> or <a><img></a>.
142
- // If there are other children than <img>, this means that the block image
143
- // has a caption or some other features and this kind of image should be
144
- // pasted/dropped without modifications.
145
- if (blockViewImage.childCount === 1) {
146
- // Pass the attributes which are present only in the <figure> to the <img>
147
- // (e.g. the style="width:10%" attribute applied by the ImageResize plugin).
148
- Array.from(blockViewImage.getAttributes())
149
- .forEach(attribute => writer.setAttribute(...attribute, imageUtils.findViewImgElement(blockViewImage)));
150
- return blockViewImage.getChild(0);
151
- }
152
- else {
153
- return blockViewImage;
154
- }
155
- });
156
- data.content = writer.createDocumentFragment(inlineViewImages);
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
+ };