@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,283 +2,224 @@
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/imagecaption/imagecaptionediting
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { Element, enablePlaceholder } from 'ckeditor5/src/engine';
12
10
  import { toWidgetEditable } from 'ckeditor5/src/widget';
13
-
14
11
  import ToggleImageCaptionCommand from './toggleimagecaptioncommand';
15
-
16
12
  import ImageUtils from '../imageutils';
17
13
  import ImageCaptionUtils from './imagecaptionutils';
18
-
19
14
  /**
20
15
  * The image caption engine plugin. It is responsible for:
21
16
  *
22
17
  * * registering converters for the caption element,
23
18
  * * registering converters for the caption model attribute,
24
19
  * * registering the {@link module:image/imagecaption/toggleimagecaptioncommand~ToggleImageCaptionCommand `toggleImageCaption`} command.
25
- *
26
- * @extends module:core/plugin~Plugin
27
20
  */
28
21
  export default class ImageCaptionEditing extends Plugin {
29
- /**
30
- * @inheritDoc
31
- */
32
- static get requires() {
33
- return [ ImageUtils, ImageCaptionUtils ];
34
- }
35
-
36
- /**
37
- * @inheritDoc
38
- */
39
- static get pluginName() {
40
- return 'ImageCaptionEditing';
41
- }
42
-
43
- /**
44
- * @inheritDoc
45
- */
46
- constructor( editor ) {
47
- super( editor );
48
-
49
- /**
50
- * A map that keeps saved JSONified image captions and image model elements they are
51
- * associated with.
52
- *
53
- * To learn more about this system, see {@link #_saveCaption}.
54
- *
55
- * @member {WeakMap.<module:engine/model/element~Element,Object>}
56
- */
57
- this._savedCaptionsMap = new WeakMap();
58
- }
59
-
60
- /**
61
- * @inheritDoc
62
- */
63
- init() {
64
- const editor = this.editor;
65
- const schema = editor.model.schema;
66
-
67
- // Schema configuration.
68
- if ( !schema.isRegistered( 'caption' ) ) {
69
- schema.register( 'caption', {
70
- allowIn: 'imageBlock',
71
- allowContentOf: '$block',
72
- isLimit: true
73
- } );
74
- } else {
75
- schema.extend( 'caption', {
76
- allowIn: 'imageBlock'
77
- } );
78
- }
79
-
80
- editor.commands.add( 'toggleImageCaption', new ToggleImageCaptionCommand( this.editor ) );
81
-
82
- this._setupConversion();
83
- this._setupImageTypeCommandsIntegration();
84
- this._registerCaptionReconversion();
85
- }
86
-
87
- /**
88
- * Configures conversion pipelines to support upcasting and downcasting
89
- * image captions.
90
- *
91
- * @private
92
- */
93
- _setupConversion() {
94
- const editor = this.editor;
95
- const view = editor.editing.view;
96
- const imageUtils = editor.plugins.get( 'ImageUtils' );
97
- const imageCaptionUtils = editor.plugins.get( 'ImageCaptionUtils' );
98
- const t = editor.t;
99
-
100
- // View -> model converter for the data pipeline.
101
- editor.conversion.for( 'upcast' ).elementToElement( {
102
- view: element => imageCaptionUtils.matchImageCaptionViewElement( element ),
103
- model: 'caption'
104
- } );
105
-
106
- // Model -> view converter for the data pipeline.
107
- editor.conversion.for( 'dataDowncast' ).elementToElement( {
108
- model: 'caption',
109
- view: ( modelElement, { writer } ) => {
110
- if ( !imageUtils.isBlockImage( modelElement.parent ) ) {
111
- return null;
112
- }
113
-
114
- return writer.createContainerElement( 'figcaption' );
115
- }
116
- } );
117
-
118
- // Model -> view converter for the editing pipeline.
119
- editor.conversion.for( 'editingDowncast' ).elementToElement( {
120
- model: 'caption',
121
- view: ( modelElement, { writer } ) => {
122
- if ( !imageUtils.isBlockImage( modelElement.parent ) ) {
123
- return null;
124
- }
125
-
126
- const figcaptionElement = writer.createEditableElement( 'figcaption' );
127
- writer.setCustomProperty( 'imageCaption', true, figcaptionElement );
128
-
129
- enablePlaceholder( {
130
- view,
131
- element: figcaptionElement,
132
- text: t( 'Enter image caption' ),
133
- keepOnFocus: true
134
- } );
135
-
136
- const imageAlt = modelElement.parent.getAttribute( 'alt' );
137
- const label = imageAlt ? t( 'Caption for image: %0', [ imageAlt ] ) : t( 'Caption for the image' );
138
-
139
- return toWidgetEditable( figcaptionElement, writer, { label } );
140
- }
141
- } );
142
- }
143
-
144
- /**
145
- * Integrates with {@link module:image/image/imagetypecommand~ImageTypeCommand image type commands}
146
- * to make sure the caption is preserved when the type of an image changes so it can be restored
147
- * in the future if the user decides they want their caption back.
148
- *
149
- * @private
150
- */
151
- _setupImageTypeCommandsIntegration() {
152
- const editor = this.editor;
153
- const imageUtils = editor.plugins.get( 'ImageUtils' );
154
- const imageCaptionUtils = editor.plugins.get( 'ImageCaptionUtils' );
155
- const imageTypeInlineCommand = editor.commands.get( 'imageTypeInline' );
156
- const imageTypeBlockCommand = editor.commands.get( 'imageTypeBlock' );
157
-
158
- const handleImageTypeChange = evt => {
159
- // The image type command execution can be unsuccessful.
160
- if ( !evt.return ) {
161
- return;
162
- }
163
-
164
- const { oldElement, newElement } = evt.return;
165
-
166
- /* istanbul ignore if: paranoid check */
167
- if ( !oldElement ) {
168
- return;
169
- }
170
-
171
- if ( imageUtils.isBlockImage( oldElement ) ) {
172
- const oldCaptionElement = imageCaptionUtils.getCaptionFromImageModelElement( oldElement );
173
-
174
- // If the old element was a captioned block image (the caption was visible),
175
- // simply save it so it can be restored.
176
- if ( oldCaptionElement ) {
177
- this._saveCaption( newElement, oldCaptionElement );
178
-
179
- return;
180
- }
181
- }
182
-
183
- const savedOldElementCaption = this._getSavedCaption( oldElement );
184
-
185
- // If either:
186
- //
187
- // * the block image didn't have a visible caption,
188
- // * the block image caption was hidden (and already saved),
189
- // * the inline image was passed
190
- //
191
- // just try to "pass" the saved caption from the old image to the new image
192
- // so it can be retrieved in the future if the user wants it back.
193
- if ( savedOldElementCaption ) {
194
- // Note: Since we're writing to a WeakMap, we don't bother with removing the
195
- // [ oldElement, savedOldElementCaption ] pair from it.
196
- this._saveCaption( newElement, savedOldElementCaption );
197
- }
198
- };
199
-
200
- // Presence of the commands depends on the Image(Inline|Block)Editing plugins loaded in the editor.
201
- if ( imageTypeInlineCommand ) {
202
- this.listenTo( imageTypeInlineCommand, 'execute', handleImageTypeChange, { priority: 'low' } );
203
- }
204
-
205
- if ( imageTypeBlockCommand ) {
206
- this.listenTo( imageTypeBlockCommand, 'execute', handleImageTypeChange, { priority: 'low' } );
207
- }
208
- }
209
-
210
- /**
211
- * Returns the saved {@link module:engine/model/element~Element#toJSON JSONified} caption
212
- * of an image model element.
213
- *
214
- * See {@link #_saveCaption}.
215
- *
216
- * @protected
217
- * @param {module:engine/model/element~Element} imageModelElement The model element the
218
- * caption should be returned for.
219
- * @returns {module:engine/model/element~Element|null} The model caption element or `null` if there is none.
220
- */
221
- _getSavedCaption( imageModelElement ) {
222
- const jsonObject = this._savedCaptionsMap.get( imageModelElement );
223
-
224
- return jsonObject ? Element.fromJSON( jsonObject ) : null;
225
- }
226
-
227
- /**
228
- * Saves a {@link module:engine/model/element~Element#toJSON JSONified} caption for
229
- * an image element to allow restoring it in the future.
230
- *
231
- * A caption is saved every time it gets hidden and/or the type of an image changes. The
232
- * user should be able to restore it on demand.
233
- *
234
- * **Note**: The caption cannot be stored in the image model element attribute because,
235
- * for instance, when the model state propagates to collaborators, the attribute would get
236
- * lost (mainly because it does not convert to anything when the caption is hidden) and
237
- * the states of collaborators' models would de-synchronize causing numerous issues.
238
- *
239
- * See {@link #_getSavedCaption}.
240
- *
241
- * @protected
242
- * @param {module:engine/model/element~Element} imageModelElement The model element the
243
- * caption is saved for.
244
- * @param {module:engine/model/element~Element} caption The caption model element to be saved.
245
- */
246
- _saveCaption( imageModelElement, caption ) {
247
- this._savedCaptionsMap.set( imageModelElement, caption.toJSON() );
248
- }
249
-
250
- /**
251
- * Reconverts image caption when image alt attribute changes.
252
- * The change of alt attribute is reflected in caption's aria-label attribute.
253
- *
254
- * @private
255
- */
256
- _registerCaptionReconversion() {
257
- const editor = this.editor;
258
- const model = editor.model;
259
- const imageUtils = editor.plugins.get( 'ImageUtils' );
260
- const imageCaptionUtils = editor.plugins.get( 'ImageCaptionUtils' );
261
-
262
- model.document.on( 'change:data', () => {
263
- const changes = model.document.differ.getChanges();
264
-
265
- for ( const change of changes ) {
266
- if ( change.attributeKey !== 'alt' ) {
267
- continue;
268
- }
269
-
270
- const image = change.range.start.nodeAfter;
271
-
272
- if ( imageUtils.isBlockImage( image ) ) {
273
- const caption = imageCaptionUtils.getCaptionFromImageModelElement( image );
274
-
275
- if ( !caption ) {
276
- return;
277
- }
278
-
279
- editor.editing.reconvertItem( caption );
280
- }
281
- }
282
- } );
283
- }
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get requires() {
26
+ return [ImageUtils, ImageCaptionUtils];
27
+ }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get pluginName() {
32
+ return 'ImageCaptionEditing';
33
+ }
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ constructor(editor) {
38
+ super(editor);
39
+ this._savedCaptionsMap = new WeakMap();
40
+ }
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ init() {
45
+ const editor = this.editor;
46
+ const schema = editor.model.schema;
47
+ // Schema configuration.
48
+ if (!schema.isRegistered('caption')) {
49
+ schema.register('caption', {
50
+ allowIn: 'imageBlock',
51
+ allowContentOf: '$block',
52
+ isLimit: true
53
+ });
54
+ }
55
+ else {
56
+ schema.extend('caption', {
57
+ allowIn: 'imageBlock'
58
+ });
59
+ }
60
+ editor.commands.add('toggleImageCaption', new ToggleImageCaptionCommand(this.editor));
61
+ this._setupConversion();
62
+ this._setupImageTypeCommandsIntegration();
63
+ this._registerCaptionReconversion();
64
+ }
65
+ /**
66
+ * Configures conversion pipelines to support upcasting and downcasting
67
+ * image captions.
68
+ */
69
+ _setupConversion() {
70
+ const editor = this.editor;
71
+ const view = editor.editing.view;
72
+ const imageUtils = editor.plugins.get('ImageUtils');
73
+ const imageCaptionUtils = editor.plugins.get('ImageCaptionUtils');
74
+ const t = editor.t;
75
+ // View -> model converter for the data pipeline.
76
+ editor.conversion.for('upcast').elementToElement({
77
+ view: element => imageCaptionUtils.matchImageCaptionViewElement(element),
78
+ model: 'caption'
79
+ });
80
+ // Model -> view converter for the data pipeline.
81
+ editor.conversion.for('dataDowncast').elementToElement({
82
+ model: 'caption',
83
+ view: (modelElement, { writer }) => {
84
+ if (!imageUtils.isBlockImage(modelElement.parent)) {
85
+ return null;
86
+ }
87
+ return writer.createContainerElement('figcaption');
88
+ }
89
+ });
90
+ // Model -> view converter for the editing pipeline.
91
+ editor.conversion.for('editingDowncast').elementToElement({
92
+ model: 'caption',
93
+ view: (modelElement, { writer }) => {
94
+ if (!imageUtils.isBlockImage(modelElement.parent)) {
95
+ return null;
96
+ }
97
+ const figcaptionElement = writer.createEditableElement('figcaption');
98
+ writer.setCustomProperty('imageCaption', true, figcaptionElement);
99
+ enablePlaceholder({
100
+ view,
101
+ element: figcaptionElement,
102
+ text: t('Enter image caption'),
103
+ keepOnFocus: true
104
+ });
105
+ const imageAlt = modelElement.parent.getAttribute('alt');
106
+ const label = imageAlt ? t('Caption for image: %0', [imageAlt]) : t('Caption for the image');
107
+ return toWidgetEditable(figcaptionElement, writer, { label });
108
+ }
109
+ });
110
+ }
111
+ /**
112
+ * Integrates with {@link module:image/image/imagetypecommand~ImageTypeCommand image type commands}
113
+ * to make sure the caption is preserved when the type of an image changes so it can be restored
114
+ * in the future if the user decides they want their caption back.
115
+ */
116
+ _setupImageTypeCommandsIntegration() {
117
+ const editor = this.editor;
118
+ const imageUtils = editor.plugins.get('ImageUtils');
119
+ const imageCaptionUtils = editor.plugins.get('ImageCaptionUtils');
120
+ const imageTypeInlineCommand = editor.commands.get('imageTypeInline');
121
+ const imageTypeBlockCommand = editor.commands.get('imageTypeBlock');
122
+ const handleImageTypeChange = evt => {
123
+ // The image type command execution can be unsuccessful.
124
+ if (!evt.return) {
125
+ return;
126
+ }
127
+ const { oldElement, newElement } = evt.return;
128
+ /* istanbul ignore if: paranoid check */
129
+ if (!oldElement) {
130
+ return;
131
+ }
132
+ if (imageUtils.isBlockImage(oldElement)) {
133
+ const oldCaptionElement = imageCaptionUtils.getCaptionFromImageModelElement(oldElement);
134
+ // If the old element was a captioned block image (the caption was visible),
135
+ // simply save it so it can be restored.
136
+ if (oldCaptionElement) {
137
+ this._saveCaption(newElement, oldCaptionElement);
138
+ return;
139
+ }
140
+ }
141
+ const savedOldElementCaption = this._getSavedCaption(oldElement);
142
+ // If either:
143
+ //
144
+ // * the block image didn't have a visible caption,
145
+ // * the block image caption was hidden (and already saved),
146
+ // * the inline image was passed
147
+ //
148
+ // just try to "pass" the saved caption from the old image to the new image
149
+ // so it can be retrieved in the future if the user wants it back.
150
+ if (savedOldElementCaption) {
151
+ // Note: Since we're writing to a WeakMap, we don't bother with removing the
152
+ // [ oldElement, savedOldElementCaption ] pair from it.
153
+ this._saveCaption(newElement, savedOldElementCaption);
154
+ }
155
+ };
156
+ // Presence of the commands depends on the Image(Inline|Block)Editing plugins loaded in the editor.
157
+ if (imageTypeInlineCommand) {
158
+ this.listenTo(imageTypeInlineCommand, 'execute', handleImageTypeChange, { priority: 'low' });
159
+ }
160
+ if (imageTypeBlockCommand) {
161
+ this.listenTo(imageTypeBlockCommand, 'execute', handleImageTypeChange, { priority: 'low' });
162
+ }
163
+ }
164
+ /**
165
+ * Returns the saved {@link module:engine/model/element~Element#toJSON JSONified} caption
166
+ * of an image model element.
167
+ *
168
+ * See {@link #_saveCaption}.
169
+ *
170
+ * @internal
171
+ * @param imageModelElement The model element the caption should be returned for.
172
+ * @returns The model caption element or `null` if there is none.
173
+ */
174
+ _getSavedCaption(imageModelElement) {
175
+ const jsonObject = this._savedCaptionsMap.get(imageModelElement);
176
+ return jsonObject ? Element.fromJSON(jsonObject) : null;
177
+ }
178
+ /**
179
+ * Saves a {@link module:engine/model/element~Element#toJSON JSONified} caption for
180
+ * an image element to allow restoring it in the future.
181
+ *
182
+ * A caption is saved every time it gets hidden and/or the type of an image changes. The
183
+ * user should be able to restore it on demand.
184
+ *
185
+ * **Note**: The caption cannot be stored in the image model element attribute because,
186
+ * for instance, when the model state propagates to collaborators, the attribute would get
187
+ * lost (mainly because it does not convert to anything when the caption is hidden) and
188
+ * the states of collaborators' models would de-synchronize causing numerous issues.
189
+ *
190
+ * See {@link #_getSavedCaption}.
191
+ *
192
+ * @internal
193
+ * @param imageModelElement The model element the caption is saved for.
194
+ * @param caption The caption model element to be saved.
195
+ */
196
+ _saveCaption(imageModelElement, caption) {
197
+ this._savedCaptionsMap.set(imageModelElement, caption.toJSON());
198
+ }
199
+ /**
200
+ * Reconverts image caption when image alt attribute changes.
201
+ * The change of alt attribute is reflected in caption's aria-label attribute.
202
+ */
203
+ _registerCaptionReconversion() {
204
+ const editor = this.editor;
205
+ const model = editor.model;
206
+ const imageUtils = editor.plugins.get('ImageUtils');
207
+ const imageCaptionUtils = editor.plugins.get('ImageCaptionUtils');
208
+ model.document.on('change:data', () => {
209
+ const changes = model.document.differ.getChanges();
210
+ for (const change of changes) {
211
+ if (change.attributeKey !== 'alt') {
212
+ continue;
213
+ }
214
+ const image = change.range.start.nodeAfter;
215
+ if (imageUtils.isBlockImage(image)) {
216
+ const caption = imageCaptionUtils.getCaptionFromImageModelElement(image);
217
+ if (!caption) {
218
+ return;
219
+ }
220
+ editor.editing.reconvertItem(caption);
221
+ }
222
+ }
223
+ });
224
+ }
284
225
  }
@@ -0,0 +1,30 @@
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/imagecaption/imagecaptionui
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ /**
10
+ * The image caption UI plugin. It introduces the `'toggleImageCaption'` UI button.
11
+ */
12
+ export default class ImageCaptionUI extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get requires(): PluginDependencies;
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get pluginName(): 'ImageCaptionUI';
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ init(): void;
25
+ }
26
+ declare module '@ckeditor/ckeditor5-core' {
27
+ interface PluginsMap {
28
+ [ImageCaptionUI.pluginName]: ImageCaptionUI;
29
+ }
30
+ }
@@ -2,77 +2,60 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module image/imagecaption/imagecaptionui
8
7
  */
9
-
10
8
  import { Plugin, icons } from 'ckeditor5/src/core';
11
9
  import { ButtonView } from 'ckeditor5/src/ui';
12
10
  import ImageCaptionUtils from './imagecaptionutils';
13
-
14
11
  /**
15
12
  * The image caption UI plugin. It introduces the `'toggleImageCaption'` UI button.
16
- *
17
- * @extends module:core/plugin~Plugin
18
13
  */
19
14
  export default class ImageCaptionUI extends Plugin {
20
- /**
21
- * @inheritDoc
22
- */
23
- static get requires() {
24
- return [ ImageCaptionUtils ];
25
- }
26
-
27
- /**
28
- * @inheritDoc
29
- */
30
- static get pluginName() {
31
- return 'ImageCaptionUI';
32
- }
33
-
34
- /**
35
- * @inheritDoc
36
- */
37
- init() {
38
- const editor = this.editor;
39
- const editingView = editor.editing.view;
40
- const imageCaptionUtils = editor.plugins.get( 'ImageCaptionUtils' );
41
- const t = editor.t;
42
-
43
- editor.ui.componentFactory.add( 'toggleImageCaption', locale => {
44
- const command = editor.commands.get( 'toggleImageCaption' );
45
- const view = new ButtonView( locale );
46
-
47
- view.set( {
48
- icon: icons.caption,
49
- tooltip: true,
50
- isToggleable: true
51
- } );
52
-
53
- view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
54
- view.bind( 'label' ).to( command, 'value', value => value ? t( 'Toggle caption off' ) : t( 'Toggle caption on' ) );
55
-
56
- this.listenTo( view, 'execute', () => {
57
- editor.execute( 'toggleImageCaption', { focusCaptionOnShow: true } );
58
-
59
- // Scroll to the selection and highlight the caption if the caption showed up.
60
- const modelCaptionElement = imageCaptionUtils.getCaptionFromModelSelection( editor.model.document.selection );
61
-
62
- if ( modelCaptionElement ) {
63
- const figcaptionElement = editor.editing.mapper.toViewElement( modelCaptionElement );
64
-
65
- editingView.scrollToTheSelection();
66
-
67
- editingView.change( writer => {
68
- writer.addClass( 'image__caption_highlighted', figcaptionElement );
69
- } );
70
- }
71
-
72
- editor.editing.view.focus();
73
- } );
74
-
75
- return view;
76
- } );
77
- }
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ static get requires() {
19
+ return [ImageCaptionUtils];
20
+ }
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get pluginName() {
25
+ return 'ImageCaptionUI';
26
+ }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ init() {
31
+ const editor = this.editor;
32
+ const editingView = editor.editing.view;
33
+ const imageCaptionUtils = editor.plugins.get('ImageCaptionUtils');
34
+ const t = editor.t;
35
+ editor.ui.componentFactory.add('toggleImageCaption', locale => {
36
+ const command = editor.commands.get('toggleImageCaption');
37
+ const view = new ButtonView(locale);
38
+ view.set({
39
+ icon: icons.caption,
40
+ tooltip: true,
41
+ isToggleable: true
42
+ });
43
+ view.bind('isOn', 'isEnabled').to(command, 'value', 'isEnabled');
44
+ view.bind('label').to(command, 'value', value => value ? t('Toggle caption off') : t('Toggle caption on'));
45
+ this.listenTo(view, 'execute', () => {
46
+ editor.execute('toggleImageCaption', { focusCaptionOnShow: true });
47
+ // Scroll to the selection and highlight the caption if the caption showed up.
48
+ const modelCaptionElement = imageCaptionUtils.getCaptionFromModelSelection(editor.model.document.selection);
49
+ if (modelCaptionElement) {
50
+ const figcaptionElement = editor.editing.mapper.toViewElement(modelCaptionElement);
51
+ editingView.scrollToTheSelection();
52
+ editingView.change(writer => {
53
+ writer.addClass('image__caption_highlighted', figcaptionElement);
54
+ });
55
+ }
56
+ editor.editing.view.focus();
57
+ });
58
+ return view;
59
+ });
60
+ }
78
61
  }