@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.
Files changed (106) hide show
  1. package/build/image.js +1 -1
  2. package/package.json +40 -35
  3. package/src/autoimage.d.ts +53 -0
  4. package/src/autoimage.js +111 -160
  5. package/src/image/converters.d.ts +66 -0
  6. package/src/image/converters.js +200 -261
  7. package/src/image/imageblockediting.d.ts +57 -0
  8. package/src/image/imageblockediting.js +111 -155
  9. package/src/image/imageediting.d.ts +34 -0
  10. package/src/image/imageediting.js +53 -67
  11. package/src/image/imageinlineediting.d.ts +53 -0
  12. package/src/image/imageinlineediting.js +135 -180
  13. package/src/image/imageloadobserver.d.ts +44 -0
  14. package/src/image/imageloadobserver.js +28 -47
  15. package/src/image/imagetypecommand.d.ts +46 -0
  16. package/src/image/imagetypecommand.js +67 -95
  17. package/src/image/insertimagecommand.d.ts +72 -0
  18. package/src/image/insertimagecommand.js +95 -101
  19. package/src/image/replaceimagesourcecommand.d.ts +39 -0
  20. package/src/image/replaceimagesourcecommand.js +28 -33
  21. package/src/image/ui/utils.d.ts +25 -0
  22. package/src/image/ui/utils.js +25 -35
  23. package/src/image/utils.d.ts +52 -0
  24. package/src/image/utils.js +63 -90
  25. package/src/image.d.ts +38 -0
  26. package/src/image.js +13 -43
  27. package/src/imageblock.d.ts +35 -0
  28. package/src/imageblock.js +12 -21
  29. package/src/imagecaption/imagecaptionediting.d.ts +92 -0
  30. package/src/imagecaption/imagecaptionediting.js +203 -262
  31. package/src/imagecaption/imagecaptionui.d.ts +30 -0
  32. package/src/imagecaption/imagecaptionui.js +46 -63
  33. package/src/imagecaption/imagecaptionutils.d.ts +42 -0
  34. package/src/imagecaption/imagecaptionutils.js +51 -78
  35. package/src/imagecaption/toggleimagecaptioncommand.d.ts +71 -0
  36. package/src/imagecaption/toggleimagecaptioncommand.js +112 -138
  37. package/src/imagecaption.d.ts +29 -0
  38. package/src/imagecaption.js +12 -19
  39. package/src/imageconfig.d.ts +723 -0
  40. package/src/imageconfig.js +5 -0
  41. package/src/imageinline.d.ts +35 -0
  42. package/src/imageinline.js +12 -21
  43. package/src/imageinsert/imageinsertui.d.ts +49 -0
  44. package/src/imageinsert/imageinsertui.js +120 -158
  45. package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -0
  46. package/src/imageinsert/ui/imageinsertformrowview.js +37 -86
  47. package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -0
  48. package/src/imageinsert/ui/imageinsertpanelview.js +148 -258
  49. package/src/imageinsert/utils.d.ts +26 -0
  50. package/src/imageinsert/utils.js +42 -58
  51. package/src/imageinsert.d.ts +35 -0
  52. package/src/imageinsert.js +13 -84
  53. package/src/imageinsertviaurl.d.ts +34 -0
  54. package/src/imageinsertviaurl.js +12 -18
  55. package/src/imageresize/imageresizebuttons.d.ts +66 -0
  56. package/src/imageresize/imageresizebuttons.js +190 -255
  57. package/src/imageresize/imageresizeediting.d.ts +42 -0
  58. package/src/imageresize/imageresizeediting.js +100 -125
  59. package/src/imageresize/imageresizehandles.d.ts +30 -0
  60. package/src/imageresize/imageresizehandles.js +91 -123
  61. package/src/imageresize/resizeimagecommand.d.ts +47 -0
  62. package/src/imageresize/resizeimagecommand.js +48 -55
  63. package/src/imageresize.d.ts +29 -0
  64. package/src/imageresize.js +12 -209
  65. package/src/imagestyle/converters.d.ts +24 -0
  66. package/src/imagestyle/converters.js +60 -78
  67. package/src/imagestyle/imagestylecommand.d.ts +70 -0
  68. package/src/imagestyle/imagestylecommand.js +88 -124
  69. package/src/imagestyle/imagestyleediting.d.ts +54 -0
  70. package/src/imagestyle/imagestyleediting.js +90 -137
  71. package/src/imagestyle/imagestyleui.d.ts +60 -0
  72. package/src/imagestyle/imagestyleui.js +169 -277
  73. package/src/imagestyle/utils.d.ts +61 -0
  74. package/src/imagestyle/utils.js +253 -306
  75. package/src/imagestyle.d.ts +35 -0
  76. package/src/imagestyle.js +13 -261
  77. package/src/imagetextalternative/imagetextalternativecommand.d.ts +39 -0
  78. package/src/imagetextalternative/imagetextalternativecommand.js +31 -47
  79. package/src/imagetextalternative/imagetextalternativeediting.d.ts +32 -0
  80. package/src/imagetextalternative/imagetextalternativeediting.js +18 -25
  81. package/src/imagetextalternative/imagetextalternativeui.d.ts +72 -0
  82. package/src/imagetextalternative/imagetextalternativeui.js +156 -219
  83. package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -0
  84. package/src/imagetextalternative/ui/textalternativeformview.js +103 -192
  85. package/src/imagetextalternative.d.ts +32 -0
  86. package/src/imagetextalternative.js +12 -18
  87. package/src/imagetoolbar.d.ts +38 -0
  88. package/src/imagetoolbar.js +31 -77
  89. package/src/imageupload/imageuploadediting.d.ts +114 -0
  90. package/src/imageupload/imageuploadediting.js +308 -427
  91. package/src/imageupload/imageuploadprogress.d.ts +47 -0
  92. package/src/imageupload/imageuploadprogress.js +180 -261
  93. package/src/imageupload/imageuploadui.d.ts +29 -0
  94. package/src/imageupload/imageuploadui.js +41 -57
  95. package/src/imageupload/uploadimagecommand.d.ts +65 -0
  96. package/src/imageupload/uploadimagecommand.js +73 -87
  97. package/src/imageupload/utils.d.ts +33 -0
  98. package/src/imageupload/utils.js +87 -112
  99. package/src/imageupload.d.ts +34 -0
  100. package/src/imageupload.js +12 -61
  101. package/src/imageutils.d.ts +108 -0
  102. package/src/imageutils.js +233 -329
  103. package/src/index.d.ts +31 -0
  104. package/src/index.js +0 -2
  105. package/src/pictureediting.d.ts +86 -0
  106. package/src/pictureediting.js +101 -120
@@ -2,29 +2,17 @@
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/image/imageinlineediting
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
12
10
  import { UpcastWriter } from 'ckeditor5/src/engine';
13
-
14
- import {
15
- downcastImageAttribute,
16
- downcastSrcsetAttribute
17
- } from './converters';
18
-
11
+ import { downcastImageAttribute, downcastSrcsetAttribute } from './converters';
19
12
  import ImageEditing from './imageediting';
20
13
  import ImageTypeCommand from './imagetypecommand';
21
14
  import ImageUtils from '../imageutils';
22
- import {
23
- getImgViewElementMatcher,
24
- createInlineImageViewElement,
25
- determineImageTypeForInsertionAtSelection
26
- } from '../image/utils';
27
-
15
+ import { getImgViewElementMatcher, createInlineImageViewElement, determineImageTypeForInsertionAtSelection } from '../image/utils';
28
16
  /**
29
17
  * The image inline plugin.
30
18
  *
@@ -34,172 +22,139 @@ import {
34
22
  * * converters for editing and data pipelines.
35
23
  * * {@link module:image/image/imagetypecommand~ImageTypeCommand `'imageTypeInline'`} command that converts block images into
36
24
  * inline images.
37
- *
38
- * @extends module:core/plugin~Plugin
39
25
  */
40
26
  export default class ImageInlineEditing extends Plugin {
41
- /**
42
- * @inheritDoc
43
- */
44
- static get requires() {
45
- return [ ImageEditing, ImageUtils, ClipboardPipeline ];
46
- }
47
-
48
- /**
49
- * @inheritDoc
50
- */
51
- static get pluginName() {
52
- return 'ImageInlineEditing';
53
- }
54
-
55
- /**
56
- * @inheritDoc
57
- */
58
- init() {
59
- const editor = this.editor;
60
- const schema = editor.model.schema;
61
-
62
- // Converters 'alt' and 'srcset' are added in 'ImageEditing' plugin.
63
- schema.register( 'imageInline', {
64
- inheritAllFrom: '$inlineObject',
65
- allowAttributes: [ 'alt', 'src', 'srcset' ]
66
- } );
67
-
68
- // Disallow inline images in captions (for now). This is the best spot to do that because
69
- // independent packages can introduce captions (ImageCaption, TableCaption, etc.) so better this
70
- // be future-proof.
71
- schema.addChildCheck( ( context, childDefinition ) => {
72
- if ( context.endsWith( 'caption' ) && childDefinition.name === 'imageInline' ) {
73
- return false;
74
- }
75
- } );
76
-
77
- this._setupConversion();
78
-
79
- if ( editor.plugins.has( 'ImageBlockEditing' ) ) {
80
- editor.commands.add( 'imageTypeInline', new ImageTypeCommand( this.editor, 'imageInline' ) );
81
-
82
- this._setupClipboardIntegration();
83
- }
84
- }
85
-
86
- /**
87
- * Configures conversion pipelines to support upcasting and downcasting
88
- * inline images (inline image widgets) and their attributes.
89
- *
90
- * @private
91
- */
92
- _setupConversion() {
93
- const editor = this.editor;
94
- const t = editor.t;
95
- const conversion = editor.conversion;
96
- const imageUtils = editor.plugins.get( 'ImageUtils' );
97
-
98
- conversion.for( 'dataDowncast' )
99
- .elementToElement( {
100
- model: 'imageInline',
101
- view: ( modelElement, { writer } ) => writer.createEmptyElement( 'img' )
102
- } );
103
-
104
- conversion.for( 'editingDowncast' )
105
- .elementToStructure( {
106
- model: 'imageInline',
107
- view: ( modelElement, { writer } ) => imageUtils.toImageWidget(
108
- createInlineImageViewElement( writer ), writer, t( 'image widget' )
109
- )
110
- } );
111
-
112
- conversion.for( 'downcast' )
113
- .add( downcastImageAttribute( imageUtils, 'imageInline', 'src' ) )
114
- .add( downcastImageAttribute( imageUtils, 'imageInline', 'alt' ) )
115
- .add( downcastSrcsetAttribute( imageUtils, 'imageInline' ) );
116
-
117
- // More image related upcasts are in 'ImageEditing' plugin.
118
- conversion.for( 'upcast' )
119
- .elementToElement( {
120
- view: getImgViewElementMatcher( editor, 'imageInline' ),
121
- model: ( viewImage, { writer } ) => writer.createElement(
122
- 'imageInline',
123
- viewImage.hasAttribute( 'src' ) ? { src: viewImage.getAttribute( 'src' ) } : null
124
- )
125
- } );
126
- }
127
-
128
- /**
129
- * Integrates the plugin with the clipboard pipeline.
130
- *
131
- * Idea is that the feature should recognize the user's intent when an **block** image is
132
- * pasted or dropped. If such an image is pasted/dropped into a non-empty block
133
- * (e.g. a paragraph with some text) it gets converted into an inline image on the fly.
134
- *
135
- * We assume this is the user's intent if they decided to put their image there.
136
- *
137
- * **Note**: If a block image has a caption, it will not be converted to an inline image
138
- * to avoid the confusion. Captions are added on purpose and they should never be lost
139
- * in the clipboard pipeline.
140
- *
141
- * See the `ImageBlockEditing` for the similar integration that works in the opposite direction.
142
- *
143
- * @private
144
- */
145
- _setupClipboardIntegration() {
146
- const editor = this.editor;
147
- const model = editor.model;
148
- const editingView = editor.editing.view;
149
- const imageUtils = editor.plugins.get( 'ImageUtils' );
150
-
151
- this.listenTo( editor.plugins.get( 'ClipboardPipeline' ), 'inputTransformation', ( evt, data ) => {
152
- const docFragmentChildren = Array.from( data.content.getChildren() );
153
- let modelRange;
154
-
155
- // Make sure only <figure class="image"></figure> elements are dropped or pasted. Otherwise, if there some other HTML
156
- // mixed up, this should be handled as a regular paste.
157
- if ( !docFragmentChildren.every( imageUtils.isBlockImageView ) ) {
158
- return;
159
- }
160
-
161
- // When drag and dropping, data.targetRanges specifies where to drop because
162
- // this is usually a different place than the current model selection (the user
163
- // uses a drop marker to specify the drop location).
164
- if ( data.targetRanges ) {
165
- modelRange = editor.editing.mapper.toModelRange( data.targetRanges[ 0 ] );
166
- }
167
- // Pasting, however, always occurs at the current model selection.
168
- else {
169
- modelRange = model.document.selection.getFirstRange();
170
- }
171
-
172
- const selection = model.createSelection( modelRange );
173
-
174
- // Convert block images into inline images only when pasting or dropping into non-empty blocks
175
- // and when the block is not an object (e.g. pasting to replace another widget).
176
- if ( determineImageTypeForInsertionAtSelection( model.schema, selection ) === 'imageInline' ) {
177
- const writer = new UpcastWriter( editingView.document );
178
-
179
- // Unwrap <figure class="image"><img .../></figure> -> <img ... />
180
- // but <figure class="image"><img .../><figcaption>...</figcaption></figure> -> stays the same
181
- const inlineViewImages = docFragmentChildren.map( blockViewImage => {
182
- // If there's just one child, it can be either <img /> or <a><img></a>.
183
- // If there are other children than <img>, this means that the block image
184
- // has a caption or some other features and this kind of image should be
185
- // pasted/dropped without modifications.
186
- if ( blockViewImage.childCount === 1 ) {
187
- // Pass the attributes which are present only in the <figure> to the <img>
188
- // (e.g. the style="width:10%" attribute applied by the ImageResize plugin).
189
- Array.from( blockViewImage.getAttributes() )
190
- .forEach( attribute => writer.setAttribute(
191
- ...attribute,
192
- imageUtils.findViewImgElement( blockViewImage )
193
- ) );
194
-
195
- return blockViewImage.getChild( 0 );
196
- } else {
197
- return blockViewImage;
198
- }
199
- } );
200
-
201
- data.content = writer.createDocumentFragment( inlineViewImages );
202
- }
203
- } );
204
- }
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
+ }
205
160
  }
@@ -0,0 +1,44 @@
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
+ * Fires {@link module:engine/view/document~Document#event:layoutChanged} and
24
+ * {@link module:engine/view/document~Document#event:imageLoaded}
25
+ * if observer {@link #isEnabled is enabled}.
26
+ *
27
+ * @param domEvent The DOM event.
28
+ */
29
+ private _fireEvents;
30
+ }
31
+ /**
32
+ * Fired when an <img/> DOM element has been loaded in the DOM root.
33
+ *
34
+ * Introduced by {@link module:image/image/imageloadobserver~ImageLoadObserver}.
35
+ *
36
+ * @see module:image/image/imageloadobserver~ImageLoadObserver
37
+ *
38
+ * @eventName imageLoaded
39
+ * @param data Event data.
40
+ */
41
+ export type ImageLoadedEvent = {
42
+ name: 'imageLoaded';
43
+ args: [Event];
44
+ };
@@ -2,13 +2,10 @@
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/image/imageloadobserver
8
7
  */
9
-
10
8
  import { Observer } from 'ckeditor5/src/engine';
11
-
12
9
  /**
13
10
  * Observes all new images added to the {@link module:engine/view/document~Document},
14
11
  * fires {@link module:engine/view/document~Document#event:imageLoaded} and
@@ -16,50 +13,34 @@ import { Observer } from 'ckeditor5/src/engine';
16
13
  * has been loaded.
17
14
  *
18
15
  * **Note:** This event is not fired for images that has been added to the document and rendered as `complete` (already loaded).
19
- *
20
- * @extends module:engine/view/observer/observer~Observer
21
16
  */
22
17
  export default class ImageLoadObserver extends Observer {
23
- /**
24
- * @inheritDoc
25
- */
26
- observe( domRoot ) {
27
- this.listenTo( domRoot, 'load', ( event, domEvent ) => {
28
- const domElement = domEvent.target;
29
-
30
- if ( this.checkShouldIgnoreEventFromTarget( domElement ) ) {
31
- return;
32
- }
33
-
34
- if ( domElement.tagName == 'IMG' ) {
35
- this._fireEvents( domEvent );
36
- }
37
- // Use capture phase for better performance (#4504).
38
- }, { useCapture: true } );
39
- }
40
-
41
- /**
42
- * Fires {@link module:engine/view/document~Document#event:layoutChanged} and
43
- * {@link module:engine/view/document~Document#event:imageLoaded}
44
- * if observer {@link #isEnabled is enabled}.
45
- *
46
- * @protected
47
- * @param {Event} domEvent The DOM event.
48
- */
49
- _fireEvents( domEvent ) {
50
- if ( this.isEnabled ) {
51
- this.document.fire( 'layoutChanged' );
52
- this.document.fire( 'imageLoaded', domEvent );
53
- }
54
- }
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ observe(domRoot) {
22
+ this.listenTo(domRoot, 'load', (event, domEvent) => {
23
+ const domElement = domEvent.target;
24
+ if (this.checkShouldIgnoreEventFromTarget(domElement)) {
25
+ return;
26
+ }
27
+ if (domElement.tagName == 'IMG') {
28
+ this._fireEvents(domEvent);
29
+ }
30
+ // Use capture phase for better performance (#4504).
31
+ }, { useCapture: true });
32
+ }
33
+ /**
34
+ * Fires {@link module:engine/view/document~Document#event:layoutChanged} and
35
+ * {@link module:engine/view/document~Document#event:imageLoaded}
36
+ * if observer {@link #isEnabled is enabled}.
37
+ *
38
+ * @param domEvent The DOM event.
39
+ */
40
+ _fireEvents(domEvent) {
41
+ if (this.isEnabled) {
42
+ this.document.fire('layoutChanged');
43
+ this.document.fire('imageLoaded', domEvent);
44
+ }
45
+ }
55
46
  }
56
-
57
- /**
58
- * Fired when an <img/> DOM element has been loaded in the DOM root.
59
- *
60
- * Introduced by {@link module:image/image/imageloadobserver~ImageLoadObserver}.
61
- *
62
- * @see module:image/image/imageloadobserver~ImageLoadObserver
63
- * @event module:engine/view/document~Document#event:imageLoaded
64
- * @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
65
- */
@@ -0,0 +1,46 @@
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/imagetypecommand
7
+ */
8
+ import type { Element } from 'ckeditor5/src/engine';
9
+ import { Command, type Editor } from 'ckeditor5/src/core';
10
+ /**
11
+ * The image type command. It changes the type of a selected image, depending on the configuration.
12
+ */
13
+ export default class ImageTypeCommand extends Command {
14
+ /**
15
+ * Model element name the command converts to.
16
+ */
17
+ private readonly _modelElementName;
18
+ /**
19
+ * @inheritDoc
20
+ *
21
+ * @param modelElementName Model element name the command converts to.
22
+ */
23
+ constructor(editor: Editor, modelElementName: 'imageBlock' | 'imageInline');
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ refresh(): void;
28
+ /**
29
+ * Executes the command and changes the type of a selected image.
30
+ *
31
+ * @fires execute
32
+ * @returns An object containing references to old and new model image elements
33
+ * (for before and after the change) so external integrations can hook into the decorated
34
+ * `execute` event and handle this change. `null` if the type change failed.
35
+ */
36
+ execute(): {
37
+ oldElement: Element;
38
+ newElement: Element;
39
+ } | null;
40
+ }
41
+ declare module '@ckeditor/ckeditor5-core' {
42
+ interface CommandsMap {
43
+ imageTypeBlock: ImageTypeCommand;
44
+ imageTypeInline: ImageTypeCommand;
45
+ }
46
+ }