@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
package/src/imageutils.js CHANGED
@@ -2,344 +2,248 @@
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/imageutils
8
- */
9
-
10
5
  import { Plugin } from 'ckeditor5/src/core';
11
6
  import { findOptimalInsertionRange, isWidget, toWidget } from 'ckeditor5/src/widget';
12
7
  import { determineImageTypeForInsertionAtSelection } from './image/utils';
13
-
8
+ import './imageconfig';
14
9
  /**
15
10
  * A set of helpers related to images.
16
- *
17
- * @extends module:core/plugin~Plugin
18
11
  */
19
12
  export default class ImageUtils extends Plugin {
20
- /**
21
- * @inheritDoc
22
- */
23
- static get pluginName() {
24
- return 'ImageUtils';
25
- }
26
-
27
- /**
28
- * Checks if the provided model element is an `image` or `imageInline`.
29
- *
30
- * @param {module:engine/model/element~Element} modelElement
31
- * @returns {Boolean}
32
- */
33
- isImage( modelElement ) {
34
- return this.isInlineImage( modelElement ) || this.isBlockImage( modelElement );
35
- }
36
-
37
- /**
38
- * Checks if the provided view element represents an inline image.
39
- *
40
- * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
41
- *
42
- * @param {module:engine/view/element~Element} element
43
- * @returns {Boolean}
44
- */
45
- isInlineImageView( element ) {
46
- return !!element && element.is( 'element', 'img' );
47
- }
48
-
49
- /**
50
- * Checks if the provided view element represents a block image.
51
- *
52
- * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
53
- *
54
- * @param {module:engine/view/element~Element} element
55
- * @returns {Boolean}
56
- */
57
- isBlockImageView( element ) {
58
- return !!element && element.is( 'element', 'figure' ) && element.hasClass( 'image' );
59
- }
60
-
61
- /**
62
- * Handles inserting single file. This method unifies image insertion using {@link module:widget/utils~findOptimalInsertionRange}
63
- * method.
64
- *
65
- * const imageUtils = editor.plugins.get( 'ImageUtils' );
66
- *
67
- * imageUtils.insertImage( { src: 'path/to/image.jpg' } );
68
- *
69
- * @param {Object} [attributes={}] Attributes of the inserted image.
70
- * This method filters out the attributes which are disallowed by the {@link module:engine/model/schema~Schema}.
71
- * @param {module:engine/model/selection~Selectable} [selectable] Place to insert the image. If not specified,
72
- * the {@link module:widget/utils~findOptimalInsertionRange} logic will be applied for the block images
73
- * and `model.document.selection` for the inline images.
74
- *
75
- * **Note**: If `selectable` is passed, this helper will not be able to set selection attributes (such as `linkHref`)
76
- * and apply them to the new image. In this case, make sure all selection attributes are passed in `attributes`.
77
- *
78
- * @param {'imageBlock'|'imageInline'} [imageType] Image type of inserted image. If not specified,
79
- * it will be determined automatically depending of editor config or place of the insertion.
80
- * @return {module:engine/view/element~Element|null} The inserted model image element.
81
- */
82
- insertImage( attributes = {}, selectable = null, imageType = null ) {
83
- const editor = this.editor;
84
- const model = editor.model;
85
- const selection = model.document.selection;
86
-
87
- imageType = determineImageTypeForInsertion( editor, selectable || selection, imageType );
88
-
89
- // Mix declarative attributes with selection attributes because the new image should "inherit"
90
- // the latter for best UX. For instance, inline images inserted into existing links
91
- // should not split them. To do that, they need to have "linkHref" inherited from the selection.
92
- attributes = {
93
- ...Object.fromEntries( selection.getAttributes() ),
94
- ...attributes
95
- };
96
-
97
- for ( const attributeName in attributes ) {
98
- if ( !model.schema.checkAttribute( imageType, attributeName ) ) {
99
- delete attributes[ attributeName ];
100
- }
101
- }
102
-
103
- return model.change( writer => {
104
- const imageElement = writer.createElement( imageType, attributes );
105
-
106
- model.insertObject( imageElement, selectable, null, {
107
- setSelection: 'on',
108
- // If we want to insert a block image (for whatever reason) then we don't want to split text blocks.
109
- // This applies only when we don't have the selectable specified (i.e., we insert multiple block images at once).
110
- findOptimalPosition: !selectable && imageType != 'imageInline'
111
- } );
112
-
113
- // Inserting an image might've failed due to schema regulations.
114
- if ( imageElement.parent ) {
115
- return imageElement;
116
- }
117
-
118
- return null;
119
- } );
120
- }
121
-
122
- /**
123
- * Returns an image widget editing view element if one is selected or is among the selection's ancestors.
124
- *
125
- * @protected
126
- * @param {module:engine/view/selection~Selection|module:engine/view/documentselection~DocumentSelection} selection
127
- * @returns {module:engine/view/element~Element|null}
128
- */
129
- getClosestSelectedImageWidget( selection ) {
130
- const selectionPosition = selection.getFirstPosition();
131
-
132
- if ( !selectionPosition ) {
133
- return null;
134
- }
135
-
136
- const viewElement = selection.getSelectedElement();
137
-
138
- if ( viewElement && this.isImageWidget( viewElement ) ) {
139
- return viewElement;
140
- }
141
-
142
- let parent = selectionPosition.parent;
143
-
144
- while ( parent ) {
145
- if ( parent.is( 'element' ) && this.isImageWidget( parent ) ) {
146
- return parent;
147
- }
148
-
149
- parent = parent.parent;
150
- }
151
-
152
- return null;
153
- }
154
-
155
- /**
156
- * Returns a image model element if one is selected or is among the selection's ancestors.
157
- *
158
- * @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
159
- * @returns {module:engine/model/element~Element|null}
160
- */
161
- getClosestSelectedImageElement( selection ) {
162
- const selectedElement = selection.getSelectedElement();
163
-
164
- return this.isImage( selectedElement ) ? selectedElement : selection.getFirstPosition().findAncestor( 'imageBlock' );
165
- }
166
-
167
- /**
168
- * Checks if image can be inserted at current model selection.
169
- *
170
- * @protected
171
- * @returns {Boolean}
172
- */
173
- isImageAllowed() {
174
- const model = this.editor.model;
175
- const selection = model.document.selection;
176
-
177
- return isImageAllowedInParent( this.editor, selection ) && isNotInsideImage( selection );
178
- }
179
-
180
- /**
181
- * Converts a given {@link module:engine/view/element~Element} to an image widget:
182
- * * Adds a {@link module:engine/view/element~Element#_setCustomProperty custom property} allowing to recognize the image widget
183
- * element.
184
- * * Calls the {@link module:widget/utils~toWidget} function with the proper element's label creator.
185
- *
186
- * @protected
187
- * @param {module:engine/view/element~Element} viewElement
188
- * @param {module:engine/view/downcastwriter~DowncastWriter} writer An instance of the view writer.
189
- * @param {String} label The element's label. It will be concatenated with the image `alt` attribute if one is present.
190
- * @returns {module:engine/view/element~Element}
191
- */
192
- toImageWidget( viewElement, writer, label ) {
193
- writer.setCustomProperty( 'image', true, viewElement );
194
-
195
- const labelCreator = () => {
196
- const imgElement = this.findViewImgElement( viewElement );
197
- const altText = imgElement.getAttribute( 'alt' );
198
-
199
- return altText ? `${ altText } ${ label }` : label;
200
- };
201
-
202
- return toWidget( viewElement, writer, { label: labelCreator } );
203
- }
204
-
205
- /**
206
- * Checks if a given view element is an image widget.
207
- *
208
- * @protected
209
- * @param {module:engine/view/element~Element} viewElement
210
- * @returns {Boolean}
211
- */
212
- isImageWidget( viewElement ) {
213
- return !!viewElement.getCustomProperty( 'image' ) && isWidget( viewElement );
214
- }
215
-
216
- /**
217
- * Checks if the provided model element is an `image`.
218
- *
219
- * @param {module:engine/model/element~Element} modelElement
220
- * @returns {Boolean}
221
- */
222
- isBlockImage( modelElement ) {
223
- return !!modelElement && modelElement.is( 'element', 'imageBlock' );
224
- }
225
-
226
- /**
227
- * Checks if the provided model element is an `imageInline`.
228
- *
229
- * @param {module:engine/model/element~Element} modelElement
230
- * @returns {Boolean}
231
- */
232
- isInlineImage( modelElement ) {
233
- return !!modelElement && modelElement.is( 'element', 'imageInline' );
234
- }
235
-
236
- /**
237
- * Get the view `<img>` from another view element, e.g. a widget (`<figure class="image">`), a link (`<a>`).
238
- *
239
- * The `<img>` can be located deep in other elements, so this helper performs a deep tree search.
240
- *
241
- * @param {module:engine/view/element~Element} figureView
242
- * @returns {module:engine/view/element~Element}
243
- */
244
- findViewImgElement( figureView ) {
245
- if ( this.isInlineImageView( figureView ) ) {
246
- return figureView;
247
- }
248
-
249
- const editingView = this.editor.editing.view;
250
-
251
- for ( const { item } of editingView.createRangeIn( figureView ) ) {
252
- if ( this.isInlineImageView( item ) ) {
253
- return item;
254
- }
255
- }
256
- }
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get pluginName() {
17
+ return 'ImageUtils';
18
+ }
19
+ /**
20
+ * Checks if the provided model element is an `image` or `imageInline`.
21
+ */
22
+ isImage(modelElement) {
23
+ return this.isInlineImage(modelElement) || this.isBlockImage(modelElement);
24
+ }
25
+ /**
26
+ * Checks if the provided view element represents an inline image.
27
+ *
28
+ * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
29
+ */
30
+ isInlineImageView(element) {
31
+ return !!element && element.is('element', 'img');
32
+ }
33
+ /**
34
+ * Checks if the provided view element represents a block image.
35
+ *
36
+ * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
37
+ */
38
+ isBlockImageView(element) {
39
+ return !!element && element.is('element', 'figure') && element.hasClass('image');
40
+ }
41
+ /**
42
+ * Handles inserting single file. This method unifies image insertion using {@link module:widget/utils~findOptimalInsertionRange}
43
+ * method.
44
+ *
45
+ * ```ts
46
+ * const imageUtils = editor.plugins.get( 'ImageUtils' );
47
+ *
48
+ * imageUtils.insertImage( { src: 'path/to/image.jpg' } );
49
+ * ```
50
+ *
51
+ * @param attributes Attributes of the inserted image.
52
+ * This method filters out the attributes which are disallowed by the {@link module:engine/model/schema~Schema}.
53
+ * @param selectable Place to insert the image. If not specified,
54
+ * the {@link module:widget/utils~findOptimalInsertionRange} logic will be applied for the block images
55
+ * and `model.document.selection` for the inline images.
56
+ *
57
+ * **Note**: If `selectable` is passed, this helper will not be able to set selection attributes (such as `linkHref`)
58
+ * and apply them to the new image. In this case, make sure all selection attributes are passed in `attributes`.
59
+ *
60
+ * @param imageType Image type of inserted image. If not specified,
61
+ * it will be determined automatically depending of editor config or place of the insertion.
62
+ * @return The inserted model image element.
63
+ */
64
+ insertImage(attributes = {}, selectable = null, imageType = null) {
65
+ const editor = this.editor;
66
+ const model = editor.model;
67
+ const selection = model.document.selection;
68
+ imageType = determineImageTypeForInsertion(editor, selectable || selection, imageType);
69
+ // Mix declarative attributes with selection attributes because the new image should "inherit"
70
+ // the latter for best UX. For instance, inline images inserted into existing links
71
+ // should not split them. To do that, they need to have "linkHref" inherited from the selection.
72
+ attributes = {
73
+ ...Object.fromEntries(selection.getAttributes()),
74
+ ...attributes
75
+ };
76
+ for (const attributeName in attributes) {
77
+ if (!model.schema.checkAttribute(imageType, attributeName)) {
78
+ delete attributes[attributeName];
79
+ }
80
+ }
81
+ return model.change(writer => {
82
+ const imageElement = writer.createElement(imageType, attributes);
83
+ model.insertObject(imageElement, selectable, null, {
84
+ setSelection: 'on',
85
+ // If we want to insert a block image (for whatever reason) then we don't want to split text blocks.
86
+ // This applies only when we don't have the selectable specified (i.e., we insert multiple block images at once).
87
+ findOptimalPosition: !selectable && imageType != 'imageInline' ? 'auto' : undefined
88
+ });
89
+ // Inserting an image might've failed due to schema regulations.
90
+ if (imageElement.parent) {
91
+ return imageElement;
92
+ }
93
+ return null;
94
+ });
95
+ }
96
+ /**
97
+ * Returns an image widget editing view element if one is selected or is among the selection's ancestors.
98
+ */
99
+ getClosestSelectedImageWidget(selection) {
100
+ const selectionPosition = selection.getFirstPosition();
101
+ if (!selectionPosition) {
102
+ return null;
103
+ }
104
+ const viewElement = selection.getSelectedElement();
105
+ if (viewElement && this.isImageWidget(viewElement)) {
106
+ return viewElement;
107
+ }
108
+ let parent = selectionPosition.parent;
109
+ while (parent) {
110
+ if (parent.is('element') && this.isImageWidget(parent)) {
111
+ return parent;
112
+ }
113
+ parent = parent.parent;
114
+ }
115
+ return null;
116
+ }
117
+ /**
118
+ * Returns a image model element if one is selected or is among the selection's ancestors.
119
+ */
120
+ getClosestSelectedImageElement(selection) {
121
+ const selectedElement = selection.getSelectedElement();
122
+ return this.isImage(selectedElement) ? selectedElement : selection.getFirstPosition().findAncestor('imageBlock');
123
+ }
124
+ /**
125
+ * Checks if image can be inserted at current model selection.
126
+ *
127
+ * @internal
128
+ */
129
+ isImageAllowed() {
130
+ const model = this.editor.model;
131
+ const selection = model.document.selection;
132
+ return isImageAllowedInParent(this.editor, selection) && isNotInsideImage(selection);
133
+ }
134
+ /**
135
+ * Converts a given {@link module:engine/view/element~Element} to an image widget:
136
+ * * Adds a {@link module:engine/view/element~Element#_setCustomProperty custom property} allowing to recognize the image widget
137
+ * element.
138
+ * * Calls the {@link module:widget/utils~toWidget} function with the proper element's label creator.
139
+ *
140
+ * @param writer An instance of the view writer.
141
+ * @param label The element's label. It will be concatenated with the image `alt` attribute if one is present.
142
+ */
143
+ toImageWidget(viewElement, writer, label) {
144
+ writer.setCustomProperty('image', true, viewElement);
145
+ const labelCreator = () => {
146
+ const imgElement = this.findViewImgElement(viewElement);
147
+ const altText = imgElement.getAttribute('alt');
148
+ return altText ? `${altText} ${label}` : label;
149
+ };
150
+ return toWidget(viewElement, writer, { label: labelCreator });
151
+ }
152
+ /**
153
+ * Checks if a given view element is an image widget.
154
+ */
155
+ isImageWidget(viewElement) {
156
+ return !!viewElement.getCustomProperty('image') && isWidget(viewElement);
157
+ }
158
+ /**
159
+ * Checks if the provided model element is an `image`.
160
+ */
161
+ isBlockImage(modelElement) {
162
+ return !!modelElement && modelElement.is('element', 'imageBlock');
163
+ }
164
+ /**
165
+ * Checks if the provided model element is an `imageInline`.
166
+ */
167
+ isInlineImage(modelElement) {
168
+ return !!modelElement && modelElement.is('element', 'imageInline');
169
+ }
170
+ /**
171
+ * Get the view `<img>` from another view element, e.g. a widget (`<figure class="image">`), a link (`<a>`).
172
+ *
173
+ * The `<img>` can be located deep in other elements, so this helper performs a deep tree search.
174
+ */
175
+ findViewImgElement(figureView) {
176
+ if (this.isInlineImageView(figureView)) {
177
+ return figureView;
178
+ }
179
+ const editingView = this.editor.editing.view;
180
+ for (const { item } of editingView.createRangeIn(figureView)) {
181
+ if (this.isInlineImageView(item)) {
182
+ return item;
183
+ }
184
+ }
185
+ }
257
186
  }
258
-
259
- // Checks if image is allowed by schema in optimal insertion parent.
260
- //
261
- // @private
262
- // @param {module:core/editor/editor~Editor} editor
263
- // @param {module:engine/model/selection~Selection} selection
264
- // @returns {Boolean}
265
- function isImageAllowedInParent( editor, selection ) {
266
- const imageType = determineImageTypeForInsertion( editor, selection );
267
-
268
- if ( imageType == 'imageBlock' ) {
269
- const parent = getInsertImageParent( selection, editor.model );
270
-
271
- if ( editor.model.schema.checkChild( parent, 'imageBlock' ) ) {
272
- return true;
273
- }
274
- } else if ( editor.model.schema.checkChild( selection.focus, 'imageInline' ) ) {
275
- return true;
276
- }
277
-
278
- return false;
187
+ /**
188
+ * Checks if image is allowed by schema in optimal insertion parent.
189
+ */
190
+ function isImageAllowedInParent(editor, selection) {
191
+ const imageType = determineImageTypeForInsertion(editor, selection, null);
192
+ if (imageType == 'imageBlock') {
193
+ const parent = getInsertImageParent(selection, editor.model);
194
+ if (editor.model.schema.checkChild(parent, 'imageBlock')) {
195
+ return true;
196
+ }
197
+ }
198
+ else if (editor.model.schema.checkChild(selection.focus, 'imageInline')) {
199
+ return true;
200
+ }
201
+ return false;
279
202
  }
280
-
281
- // Checks if selection is not placed inside an image (e.g. its caption).
282
- //
283
- // @private
284
- // @param {module:engine/model/selection~Selectable} selection
285
- // @returns {Boolean}
286
- function isNotInsideImage( selection ) {
287
- return [ ...selection.focus.getAncestors() ].every( ancestor => !ancestor.is( 'element', 'imageBlock' ) );
203
+ /**
204
+ * Checks if selection is not placed inside an image (e.g. its caption).
205
+ */
206
+ function isNotInsideImage(selection) {
207
+ return [...selection.focus.getAncestors()].every(ancestor => !ancestor.is('element', 'imageBlock'));
288
208
  }
289
-
290
- // Returns a node that will be used to insert image with `model.insertContent`.
291
- //
292
- // @private
293
- // @param {module:engine/model/selection~Selection} selection
294
- // @param {module:engine/model/model~Model} model
295
- // @returns {module:engine/model/element~Element}
296
- function getInsertImageParent( selection, model ) {
297
- const insertionRange = findOptimalInsertionRange( selection, model );
298
- const parent = insertionRange.start.parent;
299
-
300
- if ( parent.isEmpty && !parent.is( 'element', '$root' ) ) {
301
- return parent.parent;
302
- }
303
-
304
- return parent;
209
+ /**
210
+ * Returns a node that will be used to insert image with `model.insertContent`.
211
+ */
212
+ function getInsertImageParent(selection, model) {
213
+ const insertionRange = findOptimalInsertionRange(selection, model);
214
+ const parent = insertionRange.start.parent;
215
+ if (parent.isEmpty && !parent.is('element', '$root')) {
216
+ return parent.parent;
217
+ }
218
+ return parent;
305
219
  }
306
-
307
- // Determine image element type name depending on editor config or place of insertion.
308
- //
309
- // @private
310
- // @param {module:core/editor/editor~Editor} editor
311
- // @param {module:engine/model/selection~Selectable} selectable
312
- // @param {'imageBlock'|'imageInline'} [imageType] Image element type name. Used to force return of provided element name,
313
- // but only if there is proper plugin enabled.
314
- // @returns {'imageBlock'|'imageInline'} imageType
315
- function determineImageTypeForInsertion( editor, selectable, imageType ) {
316
- const schema = editor.model.schema;
317
- const configImageInsertType = editor.config.get( 'image.insert.type' );
318
-
319
- if ( !editor.plugins.has( 'ImageBlockEditing' ) ) {
320
- return 'imageInline';
321
- }
322
-
323
- if ( !editor.plugins.has( 'ImageInlineEditing' ) ) {
324
- return 'imageBlock';
325
- }
326
-
327
- if ( imageType ) {
328
- return imageType;
329
- }
330
-
331
- if ( configImageInsertType === 'inline' ) {
332
- return 'imageInline';
333
- }
334
-
335
- if ( configImageInsertType === 'block' ) {
336
- return 'imageBlock';
337
- }
338
-
339
- // Try to replace the selected widget (e.g. another image).
340
- if ( selectable.is( 'selection' ) ) {
341
- return determineImageTypeForInsertionAtSelection( schema, selectable );
342
- }
343
-
344
- return schema.checkChild( selectable, 'imageInline' ) ? 'imageInline' : 'imageBlock';
220
+ /**
221
+ * Determine image element type name depending on editor config or place of insertion.
222
+ *
223
+ * @param imageType Image element type name. Used to force return of provided element name,
224
+ * but only if there is proper plugin enabled.
225
+ */
226
+ function determineImageTypeForInsertion(editor, selectable, imageType) {
227
+ const schema = editor.model.schema;
228
+ const configImageInsertType = editor.config.get('image.insert.type');
229
+ if (!editor.plugins.has('ImageBlockEditing')) {
230
+ return 'imageInline';
231
+ }
232
+ if (!editor.plugins.has('ImageInlineEditing')) {
233
+ return 'imageBlock';
234
+ }
235
+ if (imageType) {
236
+ return imageType;
237
+ }
238
+ if (configImageInsertType === 'inline') {
239
+ return 'imageInline';
240
+ }
241
+ if (configImageInsertType === 'block') {
242
+ return 'imageBlock';
243
+ }
244
+ // Try to replace the selected widget (e.g. another image).
245
+ if (selectable.is('selection')) {
246
+ return determineImageTypeForInsertionAtSelection(schema, selectable);
247
+ }
248
+ return schema.checkChild(selectable, 'imageInline') ? 'imageInline' : 'imageBlock';
345
249
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,31 @@
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
7
+ */
8
+ export { default as AutoImage } from './autoimage';
9
+ export { default as Image } from './image';
10
+ export { default as ImageEditing } from './image/imageediting';
11
+ export { default as ImageCaptionUtils } from './imagecaption/imagecaptionutils';
12
+ export { default as ImageCaption } from './imagecaption';
13
+ export { default as ImageCaptionEditing } from './imagecaption/imagecaptionediting';
14
+ export { default as ImageInsert } from './imageinsert';
15
+ export { default as ImageInsertUI } from './imageinsert/imageinsertui';
16
+ export { default as ImageResize } from './imageresize';
17
+ export { default as ImageResizeButtons } from './imageresize/imageresizebuttons';
18
+ export { default as ImageResizeEditing } from './imageresize/imageresizeediting';
19
+ export { default as ImageResizeHandles } from './imageresize/imageresizehandles';
20
+ export { default as ImageStyle } from './imagestyle';
21
+ export { default as ImageStyleEditing } from './imagestyle/imagestyleediting';
22
+ export { default as ImageStyleUI } from './imagestyle/imagestyleui';
23
+ export { default as ImageTextAlternative } from './imagetextalternative';
24
+ export { default as ImageTextAlternativeEditing } from './imagetextalternative/imagetextalternativeediting';
25
+ export { default as ImageTextAlternativeUI } from './imagetextalternative/imagetextalternativeui';
26
+ export { default as ImageToolbar } from './imagetoolbar';
27
+ export { default as ImageUpload } from './imageupload';
28
+ export { default as ImageUploadEditing, ImageUploadCompleteEvent } from './imageupload/imageuploadediting';
29
+ export { default as ImageUploadProgress } from './imageupload/imageuploadprogress';
30
+ export { default as ImageUploadUI } from './imageupload/imageuploadui';
31
+ export { default as PictureEditing } from './pictureediting';
package/src/index.js CHANGED
@@ -2,11 +2,9 @@
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
8
7
  */
9
-
10
8
  export { default as AutoImage } from './autoimage';
11
9
  export { default as Image } from './image';
12
10
  export { default as ImageEditing } from './image/imageediting';