@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.
- package/build/image.js +1 -1
- package/package.json +40 -35
- package/src/autoimage.d.ts +53 -0
- package/src/autoimage.js +111 -160
- package/src/image/converters.d.ts +66 -0
- package/src/image/converters.js +200 -261
- package/src/image/imageblockediting.d.ts +57 -0
- package/src/image/imageblockediting.js +111 -155
- package/src/image/imageediting.d.ts +34 -0
- package/src/image/imageediting.js +53 -67
- package/src/image/imageinlineediting.d.ts +53 -0
- package/src/image/imageinlineediting.js +135 -180
- package/src/image/imageloadobserver.d.ts +44 -0
- package/src/image/imageloadobserver.js +28 -47
- package/src/image/imagetypecommand.d.ts +46 -0
- package/src/image/imagetypecommand.js +67 -95
- package/src/image/insertimagecommand.d.ts +72 -0
- package/src/image/insertimagecommand.js +95 -101
- package/src/image/replaceimagesourcecommand.d.ts +39 -0
- package/src/image/replaceimagesourcecommand.js +28 -33
- package/src/image/ui/utils.d.ts +25 -0
- package/src/image/ui/utils.js +25 -35
- package/src/image/utils.d.ts +52 -0
- package/src/image/utils.js +63 -90
- package/src/image.d.ts +38 -0
- package/src/image.js +13 -43
- package/src/imageblock.d.ts +35 -0
- package/src/imageblock.js +12 -21
- package/src/imagecaption/imagecaptionediting.d.ts +92 -0
- package/src/imagecaption/imagecaptionediting.js +203 -262
- package/src/imagecaption/imagecaptionui.d.ts +30 -0
- package/src/imagecaption/imagecaptionui.js +46 -63
- package/src/imagecaption/imagecaptionutils.d.ts +42 -0
- package/src/imagecaption/imagecaptionutils.js +51 -78
- package/src/imagecaption/toggleimagecaptioncommand.d.ts +71 -0
- package/src/imagecaption/toggleimagecaptioncommand.js +112 -138
- package/src/imagecaption.d.ts +29 -0
- package/src/imagecaption.js +12 -19
- package/src/imageconfig.d.ts +723 -0
- package/src/imageconfig.js +5 -0
- package/src/imageinline.d.ts +35 -0
- package/src/imageinline.js +12 -21
- package/src/imageinsert/imageinsertui.d.ts +49 -0
- package/src/imageinsert/imageinsertui.js +120 -158
- package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -0
- package/src/imageinsert/ui/imageinsertformrowview.js +37 -86
- package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -0
- package/src/imageinsert/ui/imageinsertpanelview.js +148 -258
- package/src/imageinsert/utils.d.ts +26 -0
- package/src/imageinsert/utils.js +42 -58
- package/src/imageinsert.d.ts +35 -0
- package/src/imageinsert.js +13 -84
- package/src/imageinsertviaurl.d.ts +34 -0
- package/src/imageinsertviaurl.js +12 -18
- package/src/imageresize/imageresizebuttons.d.ts +66 -0
- package/src/imageresize/imageresizebuttons.js +190 -255
- package/src/imageresize/imageresizeediting.d.ts +42 -0
- package/src/imageresize/imageresizeediting.js +100 -125
- package/src/imageresize/imageresizehandles.d.ts +30 -0
- package/src/imageresize/imageresizehandles.js +91 -123
- package/src/imageresize/resizeimagecommand.d.ts +47 -0
- package/src/imageresize/resizeimagecommand.js +48 -55
- package/src/imageresize.d.ts +29 -0
- package/src/imageresize.js +12 -209
- package/src/imagestyle/converters.d.ts +24 -0
- package/src/imagestyle/converters.js +60 -78
- package/src/imagestyle/imagestylecommand.d.ts +70 -0
- package/src/imagestyle/imagestylecommand.js +88 -124
- package/src/imagestyle/imagestyleediting.d.ts +54 -0
- package/src/imagestyle/imagestyleediting.js +90 -137
- package/src/imagestyle/imagestyleui.d.ts +60 -0
- package/src/imagestyle/imagestyleui.js +169 -277
- package/src/imagestyle/utils.d.ts +61 -0
- package/src/imagestyle/utils.js +253 -306
- package/src/imagestyle.d.ts +35 -0
- package/src/imagestyle.js +13 -261
- package/src/imagetextalternative/imagetextalternativecommand.d.ts +39 -0
- package/src/imagetextalternative/imagetextalternativecommand.js +31 -47
- package/src/imagetextalternative/imagetextalternativeediting.d.ts +32 -0
- package/src/imagetextalternative/imagetextalternativeediting.js +18 -25
- package/src/imagetextalternative/imagetextalternativeui.d.ts +72 -0
- package/src/imagetextalternative/imagetextalternativeui.js +156 -219
- package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -0
- package/src/imagetextalternative/ui/textalternativeformview.js +103 -192
- package/src/imagetextalternative.d.ts +32 -0
- package/src/imagetextalternative.js +12 -18
- package/src/imagetoolbar.d.ts +38 -0
- package/src/imagetoolbar.js +31 -77
- package/src/imageupload/imageuploadediting.d.ts +114 -0
- package/src/imageupload/imageuploadediting.js +308 -427
- package/src/imageupload/imageuploadprogress.d.ts +47 -0
- package/src/imageupload/imageuploadprogress.js +180 -261
- package/src/imageupload/imageuploadui.d.ts +29 -0
- package/src/imageupload/imageuploadui.js +41 -57
- package/src/imageupload/uploadimagecommand.d.ts +65 -0
- package/src/imageupload/uploadimagecommand.js +73 -87
- package/src/imageupload/utils.d.ts +33 -0
- package/src/imageupload/utils.js +87 -112
- package/src/imageupload.d.ts +34 -0
- package/src/imageupload.js +12 -61
- package/src/imageutils.d.ts +108 -0
- package/src/imageutils.js +233 -329
- package/src/index.d.ts +31 -0
- package/src/index.js +0 -2
- package/src/pictureediting.d.ts +86 -0
- 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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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';
|