@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,104 +2,76 @@
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
- /**
7
- * @module image/image/imagetypecommand
8
- */
9
-
10
5
  import { Command } from 'ckeditor5/src/core';
11
-
12
6
  /**
13
7
  * The image type command. It changes the type of a selected image, depending on the configuration.
14
- *
15
- * @extends module:core/command~Command
16
8
  */
17
9
  export default class ImageTypeCommand extends Command {
18
- /**
19
- * @inheritDoc
20
- *
21
- * @param {module:core/editor/editor~Editor} editor
22
- * @param {'imageBlock'|'imageInline'} modelElementName Model element name the command converts to.
23
- */
24
- constructor( editor, modelElementName ) {
25
- super( editor );
26
-
27
- /**
28
- * Model element name the command converts to.
29
- *
30
- * @readonly
31
- * @private
32
- * @member {'imageBlock'|'imageInline'}
33
- */
34
- this._modelElementName = modelElementName;
35
- }
36
-
37
- /**
38
- * @inheritDoc
39
- */
40
- refresh() {
41
- const editor = this.editor;
42
- const imageUtils = editor.plugins.get( 'ImageUtils' );
43
- const element = imageUtils.getClosestSelectedImageElement( this.editor.model.document.selection );
44
-
45
- if ( this._modelElementName === 'imageBlock' ) {
46
- this.isEnabled = imageUtils.isInlineImage( element );
47
- } else {
48
- this.isEnabled = imageUtils.isBlockImage( element );
49
- }
50
- }
51
-
52
- /**
53
- * Executes the command and changes the type of a selected image.
54
- *
55
- * @fires execute
56
- * @returns {Object|null} An object containing references to old and new model image elements
57
- * (for before and after the change) so external integrations can hook into the decorated
58
- * `execute` event and handle this change. `null` if the type change failed.
59
- */
60
- execute() {
61
- const editor = this.editor;
62
- const model = this.editor.model;
63
- const imageUtils = editor.plugins.get( 'ImageUtils' );
64
- const oldElement = imageUtils.getClosestSelectedImageElement( model.document.selection );
65
- const attributes = Object.fromEntries( oldElement.getAttributes() );
66
-
67
- // Don't change image type if "src" is missing (a broken image), unless there's "uploadId" set.
68
- // This state may happen during image upload (before it finishes) and it should be possible to change type
69
- // of the image in the meantime.
70
- if ( !attributes.src && !attributes.uploadId ) {
71
- return null;
72
- }
73
-
74
- return model.change( writer => {
75
- // Get all markers that contain the old image element.
76
- const markers = Array.from( model.markers )
77
- .filter( marker => marker.getRange().containsItem( oldElement ) );
78
-
79
- const newElement = imageUtils.insertImage( attributes, model.createSelection( oldElement, 'on' ), this._modelElementName );
80
-
81
- if ( !newElement ) {
82
- return null;
83
- }
84
-
85
- const newElementRange = writer.createRangeOn( newElement );
86
-
87
- // Expand the previously intersecting markers' ranges to include the new image element.
88
- for ( const marker of markers ) {
89
- const markerRange = marker.getRange();
90
-
91
- // Join the survived part of the old marker range with the new element range
92
- // (loosely because there could be some new paragraph or the existing one might got split).
93
- const range = markerRange.root.rootName != '$graveyard' ?
94
- markerRange.getJoined( newElementRange, true ) : newElementRange;
95
-
96
- writer.updateMarker( marker, { range } );
97
- }
98
-
99
- return {
100
- oldElement,
101
- newElement
102
- };
103
- } );
104
- }
10
+ /**
11
+ * @inheritDoc
12
+ *
13
+ * @param modelElementName Model element name the command converts to.
14
+ */
15
+ constructor(editor, modelElementName) {
16
+ super(editor);
17
+ this._modelElementName = modelElementName;
18
+ }
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ refresh() {
23
+ const editor = this.editor;
24
+ const imageUtils = editor.plugins.get('ImageUtils');
25
+ const element = imageUtils.getClosestSelectedImageElement(this.editor.model.document.selection);
26
+ if (this._modelElementName === 'imageBlock') {
27
+ this.isEnabled = imageUtils.isInlineImage(element);
28
+ }
29
+ else {
30
+ this.isEnabled = imageUtils.isBlockImage(element);
31
+ }
32
+ }
33
+ /**
34
+ * Executes the command and changes the type of a selected image.
35
+ *
36
+ * @fires execute
37
+ * @returns An object containing references to old and new model image elements
38
+ * (for before and after the change) so external integrations can hook into the decorated
39
+ * `execute` event and handle this change. `null` if the type change failed.
40
+ */
41
+ execute() {
42
+ const editor = this.editor;
43
+ const model = this.editor.model;
44
+ const imageUtils = editor.plugins.get('ImageUtils');
45
+ const oldElement = imageUtils.getClosestSelectedImageElement(model.document.selection);
46
+ const attributes = Object.fromEntries(oldElement.getAttributes());
47
+ // Don't change image type if "src" is missing (a broken image), unless there's "uploadId" set.
48
+ // This state may happen during image upload (before it finishes) and it should be possible to change type
49
+ // of the image in the meantime.
50
+ if (!attributes.src && !attributes.uploadId) {
51
+ return null;
52
+ }
53
+ return model.change(writer => {
54
+ // Get all markers that contain the old image element.
55
+ const markers = Array.from(model.markers)
56
+ .filter(marker => marker.getRange().containsItem(oldElement));
57
+ const newElement = imageUtils.insertImage(attributes, model.createSelection(oldElement, 'on'), this._modelElementName);
58
+ if (!newElement) {
59
+ return null;
60
+ }
61
+ const newElementRange = writer.createRangeOn(newElement);
62
+ // Expand the previously intersecting markers' ranges to include the new image element.
63
+ for (const marker of markers) {
64
+ const markerRange = marker.getRange();
65
+ // Join the survived part of the old marker range with the new element range
66
+ // (loosely because there could be some new paragraph or the existing one might got split).
67
+ const range = markerRange.root.rootName != '$graveyard' ?
68
+ markerRange.getJoined(newElementRange, true) : newElementRange;
69
+ writer.updateMarker(marker, { range });
70
+ }
71
+ return {
72
+ oldElement,
73
+ newElement
74
+ };
75
+ });
76
+ }
105
77
  }
@@ -0,0 +1,72 @@
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/insertimagecommand
7
+ */
8
+ import { Command, type Editor } from 'ckeditor5/src/core';
9
+ import { type ArrayOrItem } from 'ckeditor5/src/utils';
10
+ import '../imageconfig';
11
+ /**
12
+ * Insert image command.
13
+ *
14
+ * The command is registered by the {@link module:image/image/imageediting~ImageEditing} plugin as `insertImage`
15
+ * and it is also available via aliased `imageInsert` name.
16
+ *
17
+ * In order to insert an image at the current selection position
18
+ * (according to the {@link module:widget/utils~findOptimalInsertionRange} algorithm),
19
+ * execute the command and specify the image source:
20
+ *
21
+ * ```ts
22
+ * editor.execute( 'insertImage', { source: 'http://url.to.the/image' } );
23
+ * ```
24
+ *
25
+ * It is also possible to insert multiple images at once:
26
+ *
27
+ * ```ts
28
+ * editor.execute( 'insertImage', {
29
+ * source: [
30
+ * 'path/to/image.jpg',
31
+ * 'path/to/other-image.jpg'
32
+ * ]
33
+ * } );
34
+ * ```
35
+ *
36
+ * If you want to take the full control over the process, you can specify individual model attributes:
37
+ *
38
+ * ```ts
39
+ * editor.execute( 'insertImage', {
40
+ * source: [
41
+ * { src: 'path/to/image.jpg', alt: 'First alt text' },
42
+ * { src: 'path/to/other-image.jpg', alt: 'Second alt text', customAttribute: 'My attribute value' }
43
+ * ]
44
+ * } );
45
+ * ```
46
+ */
47
+ export default class InsertImageCommand extends Command {
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ constructor(editor: Editor);
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ refresh(): void;
56
+ /**
57
+ * Executes the command.
58
+ *
59
+ * @fires execute
60
+ * @param options Options for the executed command.
61
+ * @param options.source The image source or an array of image sources to insert.
62
+ * See the documentation of the command to learn more about accepted formats.
63
+ */
64
+ execute(options: {
65
+ source: ArrayOrItem<string | Record<string, unknown>>;
66
+ }): void;
67
+ }
68
+ declare module '@ckeditor/ckeditor5-core' {
69
+ interface CommandsMap {
70
+ insertImage: InsertImageCommand;
71
+ }
72
+ }
@@ -2,14 +2,12 @@
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
- import { Command } from 'ckeditor5/src/core';
7
- import { logWarning, toArray } from 'ckeditor5/src/utils';
8
-
9
5
  /**
10
6
  * @module image/image/insertimagecommand
11
7
  */
12
-
8
+ import { Command } from 'ckeditor5/src/core';
9
+ import { logWarning, toArray } from 'ckeditor5/src/utils';
10
+ import '../imageconfig';
13
11
  /**
14
12
  * Insert image command.
15
13
  *
@@ -20,108 +18,104 @@ import { logWarning, toArray } from 'ckeditor5/src/utils';
20
18
  * (according to the {@link module:widget/utils~findOptimalInsertionRange} algorithm),
21
19
  * execute the command and specify the image source:
22
20
  *
23
- * editor.execute( 'insertImage', { source: 'http://url.to.the/image' } );
21
+ * ```ts
22
+ * editor.execute( 'insertImage', { source: 'http://url.to.the/image' } );
23
+ * ```
24
24
  *
25
25
  * It is also possible to insert multiple images at once:
26
26
  *
27
- * editor.execute( 'insertImage', {
28
- * source: [
29
- * 'path/to/image.jpg',
30
- * 'path/to/other-image.jpg'
31
- * ]
32
- * } );
27
+ * ```ts
28
+ * editor.execute( 'insertImage', {
29
+ * source: [
30
+ * 'path/to/image.jpg',
31
+ * 'path/to/other-image.jpg'
32
+ * ]
33
+ * } );
34
+ * ```
33
35
  *
34
36
  * If you want to take the full control over the process, you can specify individual model attributes:
35
37
  *
36
- * editor.execute( 'insertImage', {
37
- * source: [
38
- * { src: 'path/to/image.jpg', alt: 'First alt text' },
39
- * { src: 'path/to/other-image.jpg', alt: 'Second alt text', customAttribute: 'My attribute value' }
40
- * ]
41
- * } );
42
- *
43
- * @extends module:core/command~Command
38
+ * ```ts
39
+ * editor.execute( 'insertImage', {
40
+ * source: [
41
+ * { src: 'path/to/image.jpg', alt: 'First alt text' },
42
+ * { src: 'path/to/other-image.jpg', alt: 'Second alt text', customAttribute: 'My attribute value' }
43
+ * ]
44
+ * } );
45
+ * ```
44
46
  */
45
47
  export default class InsertImageCommand extends Command {
46
- /**
47
- * @inheritDoc
48
- */
49
- constructor( editor ) {
50
- super( editor );
51
-
52
- const configImageInsertType = editor.config.get( 'image.insert.type' );
53
-
54
- if ( !editor.plugins.has( 'ImageBlockEditing' ) ) {
55
- if ( configImageInsertType === 'block' ) {
56
- /**
57
- * The {@link module:image/imageblock~ImageBlock} plugin must be enabled to allow inserting block images. See
58
- * {@link module:image/imageinsert~ImageInsertConfig#type} to learn more.
59
- *
60
- * @error image-block-plugin-required
61
- */
62
- logWarning( 'image-block-plugin-required' );
63
- }
64
- }
65
-
66
- if ( !editor.plugins.has( 'ImageInlineEditing' ) ) {
67
- if ( configImageInsertType === 'inline' ) {
68
- /**
69
- * The {@link module:image/imageinline~ImageInline} plugin must be enabled to allow inserting inline images. See
70
- * {@link module:image/imageinsert~ImageInsertConfig#type} to learn more.
71
- *
72
- * @error image-inline-plugin-required
73
- */
74
- logWarning( 'image-inline-plugin-required' );
75
- }
76
- }
77
- }
78
-
79
- /**
80
- * @inheritDoc
81
- */
82
- refresh() {
83
- this.isEnabled = this.editor.plugins.get( 'ImageUtils' ).isImageAllowed();
84
- }
85
-
86
- /**
87
- * Executes the command.
88
- *
89
- * @fires execute
90
- * @param {Object} options Options for the executed command.
91
- * @param {String|Array.<String>|Array.<Object>} options.source The image source or an array of image sources to insert.
92
- * See the documentation of the command to learn more about accepted formats.
93
- */
94
- execute( options ) {
95
- const sourceDefinitions = toArray( options.source );
96
- const selection = this.editor.model.document.selection;
97
- const imageUtils = this.editor.plugins.get( 'ImageUtils' );
98
-
99
- // In case of multiple images, each image (starting from the 2nd) will be inserted at a position that
100
- // follows the previous one. That will move the selection and, to stay on the safe side and make sure
101
- // all images inherit the same selection attributes, they are collected beforehand.
102
- //
103
- // Applying these attributes ensures, for instance, that inserting an (inline) image into a link does
104
- // not split that link but preserves its continuity.
105
- //
106
- // Note: Selection attributes that do not make sense for images will be filtered out by insertImage() anyway.
107
- const selectionAttributes = Object.fromEntries( selection.getAttributes() );
108
-
109
- sourceDefinitions.forEach( ( sourceDefinition, index ) => {
110
- const selectedElement = selection.getSelectedElement();
111
-
112
- if ( typeof sourceDefinition === 'string' ) {
113
- sourceDefinition = { src: sourceDefinition };
114
- }
115
-
116
- // Inserting of an inline image replace the selected element and make a selection on the inserted image.
117
- // Therefore inserting multiple inline images requires creating position after each element.
118
- if ( index && selectedElement && imageUtils.isImage( selectedElement ) ) {
119
- const position = this.editor.model.createPositionAfter( selectedElement );
120
-
121
- imageUtils.insertImage( { ...sourceDefinition, ...selectionAttributes }, position );
122
- } else {
123
- imageUtils.insertImage( { ...sourceDefinition, ...selectionAttributes } );
124
- }
125
- } );
126
- }
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ constructor(editor) {
52
+ super(editor);
53
+ const configImageInsertType = editor.config.get('image.insert.type');
54
+ if (!editor.plugins.has('ImageBlockEditing')) {
55
+ if (configImageInsertType === 'block') {
56
+ /**
57
+ * The {@link module:image/imageblock~ImageBlock} plugin must be enabled to allow inserting block images. See
58
+ * {@link module:image/imageconfig~ImageInsertConfig#type} to learn more.
59
+ *
60
+ * @error image-block-plugin-required
61
+ */
62
+ logWarning('image-block-plugin-required');
63
+ }
64
+ }
65
+ if (!editor.plugins.has('ImageInlineEditing')) {
66
+ if (configImageInsertType === 'inline') {
67
+ /**
68
+ * The {@link module:image/imageinline~ImageInline} plugin must be enabled to allow inserting inline images. See
69
+ * {@link module:image/imageconfig~ImageInsertConfig#type} to learn more.
70
+ *
71
+ * @error image-inline-plugin-required
72
+ */
73
+ logWarning('image-inline-plugin-required');
74
+ }
75
+ }
76
+ }
77
+ /**
78
+ * @inheritDoc
79
+ */
80
+ refresh() {
81
+ const imageUtils = this.editor.plugins.get('ImageUtils');
82
+ this.isEnabled = imageUtils.isImageAllowed();
83
+ }
84
+ /**
85
+ * Executes the command.
86
+ *
87
+ * @fires execute
88
+ * @param options Options for the executed command.
89
+ * @param options.source The image source or an array of image sources to insert.
90
+ * See the documentation of the command to learn more about accepted formats.
91
+ */
92
+ execute(options) {
93
+ const sourceDefinitions = toArray(options.source);
94
+ const selection = this.editor.model.document.selection;
95
+ const imageUtils = this.editor.plugins.get('ImageUtils');
96
+ // In case of multiple images, each image (starting from the 2nd) will be inserted at a position that
97
+ // follows the previous one. That will move the selection and, to stay on the safe side and make sure
98
+ // all images inherit the same selection attributes, they are collected beforehand.
99
+ //
100
+ // Applying these attributes ensures, for instance, that inserting an (inline) image into a link does
101
+ // not split that link but preserves its continuity.
102
+ //
103
+ // Note: Selection attributes that do not make sense for images will be filtered out by insertImage() anyway.
104
+ const selectionAttributes = Object.fromEntries(selection.getAttributes());
105
+ sourceDefinitions.forEach((sourceDefinition, index) => {
106
+ const selectedElement = selection.getSelectedElement();
107
+ if (typeof sourceDefinition === 'string') {
108
+ sourceDefinition = { src: sourceDefinition };
109
+ }
110
+ // Inserting of an inline image replace the selected element and make a selection on the inserted image.
111
+ // Therefore inserting multiple inline images requires creating position after each element.
112
+ if (index && selectedElement && imageUtils.isImage(selectedElement)) {
113
+ const position = this.editor.model.createPositionAfter(selectedElement);
114
+ imageUtils.insertImage({ ...sourceDefinition, ...selectionAttributes }, position);
115
+ }
116
+ else {
117
+ imageUtils.insertImage({ ...sourceDefinition, ...selectionAttributes });
118
+ }
119
+ });
120
+ }
127
121
  }
@@ -0,0 +1,39 @@
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
+ import { Command } from 'ckeditor5/src/core';
6
+ /**
7
+ * @module image/image/replaceimagesourcecommand
8
+ */
9
+ /**
10
+ * Replace image source command.
11
+ *
12
+ * Changes image source to the one provided. Can be executed as follows:
13
+ *
14
+ * ```ts
15
+ * editor.execute( 'replaceImageSource', { source: 'http://url.to.the/image' } );
16
+ * ```
17
+ */
18
+ export default class ReplaceImageSourceCommand extends Command {
19
+ value: string | null;
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ refresh(): void;
24
+ /**
25
+ * Executes the command.
26
+ *
27
+ * @fires execute
28
+ * @param options Options for the executed command.
29
+ * @param options.source The image source to replace.
30
+ */
31
+ execute(options: {
32
+ source: string;
33
+ }): void;
34
+ }
35
+ declare module '@ckeditor/ckeditor5-core' {
36
+ interface CommandsMap {
37
+ replaceImageSource: ReplaceImageSourceCommand;
38
+ }
39
+ }
@@ -2,48 +2,43 @@
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
  import { Command } from 'ckeditor5/src/core';
7
-
8
6
  /**
9
7
  * @module image/image/replaceimagesourcecommand
10
8
  */
11
-
12
9
  /**
13
10
  * Replace image source command.
14
11
  *
15
12
  * Changes image source to the one provided. Can be executed as follows:
16
13
  *
17
- * editor.execute( 'replaceImageSource', { source: 'http://url.to.the/image' } );
18
- *
19
- * @extends module:core/command~Command
14
+ * ```ts
15
+ * editor.execute( 'replaceImageSource', { source: 'http://url.to.the/image' } );
16
+ * ```
20
17
  */
21
18
  export default class ReplaceImageSourceCommand extends Command {
22
- /**
23
- * @inheritDoc
24
- */
25
- refresh() {
26
- const editor = this.editor;
27
- const imageUtils = editor.plugins.get( 'ImageUtils' );
28
- const element = this.editor.model.document.selection.getSelectedElement();
29
-
30
- this.isEnabled = imageUtils.isImage( element );
31
- this.value = this.isEnabled ? element.getAttribute( 'src' ) : null;
32
- }
33
-
34
- /**
35
- * Executes the command.
36
- *
37
- * @fires execute
38
- * @param {Object} options Options for the executed command.
39
- * @param {String} [options.source] The image source to replace.
40
- */
41
- execute( options ) {
42
- const image = this.editor.model.document.selection.getSelectedElement();
43
- this.editor.model.change( writer => {
44
- writer.setAttribute( 'src', options.source, image );
45
- writer.removeAttribute( 'srcset', image );
46
- writer.removeAttribute( 'sizes', image );
47
- } );
48
- }
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ refresh() {
23
+ const editor = this.editor;
24
+ const imageUtils = editor.plugins.get('ImageUtils');
25
+ const element = this.editor.model.document.selection.getSelectedElement();
26
+ this.isEnabled = imageUtils.isImage(element);
27
+ this.value = this.isEnabled ? element.getAttribute('src') : null;
28
+ }
29
+ /**
30
+ * Executes the command.
31
+ *
32
+ * @fires execute
33
+ * @param options Options for the executed command.
34
+ * @param options.source The image source to replace.
35
+ */
36
+ execute(options) {
37
+ const image = this.editor.model.document.selection.getSelectedElement();
38
+ this.editor.model.change(writer => {
39
+ writer.setAttribute('src', options.source, image);
40
+ writer.removeAttribute('srcset', image);
41
+ writer.removeAttribute('sizes', image);
42
+ });
43
+ }
49
44
  }
@@ -0,0 +1,25 @@
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/ui/utils
7
+ */
8
+ import type { PositionOptions } from 'ckeditor5/src/utils';
9
+ import type { Editor } from 'ckeditor5/src/core';
10
+ /**
11
+ * A helper utility that positions the
12
+ * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
13
+ * with respect to the image in the editor content, if one is selected.
14
+ *
15
+ * @param editor The editor instance.
16
+ */
17
+ export declare function repositionContextualBalloon(editor: Editor): void;
18
+ /**
19
+ * Returns the positioning options that control the geometry of the
20
+ * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
21
+ * to the selected element in the editor content.
22
+ *
23
+ * @param editor The editor instance.
24
+ */
25
+ export declare function getBalloonPositionData(editor: Editor): Partial<PositionOptions>;