@ckeditor/ckeditor5-image 38.0.1 → 38.1.1
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/build/image.js.map +1 -0
- package/package.json +3 -42
- package/src/augmentation.d.ts +55 -55
- package/src/augmentation.js +5 -5
- package/src/autoimage.d.ts +52 -52
- package/src/autoimage.js +132 -132
- package/src/image/converters.d.ts +66 -66
- package/src/image/converters.js +242 -242
- package/src/image/imageblockediting.d.ts +55 -55
- package/src/image/imageblockediting.js +136 -136
- package/src/image/imageediting.d.ts +30 -30
- package/src/image/imageediting.js +74 -74
- package/src/image/imageinlineediting.d.ts +56 -56
- package/src/image/imageinlineediting.js +160 -160
- package/src/image/imageloadobserver.d.ts +48 -48
- package/src/image/imageloadobserver.js +52 -52
- package/src/image/imagetypecommand.d.ts +40 -40
- package/src/image/imagetypecommand.js +77 -77
- package/src/image/insertimagecommand.d.ts +66 -66
- package/src/image/insertimagecommand.js +120 -120
- package/src/image/replaceimagesourcecommand.d.ts +34 -34
- package/src/image/replaceimagesourcecommand.js +44 -44
- package/src/image/ui/utils.d.ts +25 -25
- package/src/image/ui/utils.js +44 -44
- package/src/image/utils.d.ts +52 -52
- package/src/image/utils.js +100 -100
- package/src/image.d.ts +34 -34
- package/src/image.js +38 -38
- package/src/imageblock.d.ts +33 -33
- package/src/imageblock.js +37 -37
- package/src/imagecaption/imagecaptionediting.d.ts +89 -89
- package/src/imagecaption/imagecaptionediting.js +225 -225
- package/src/imagecaption/imagecaptionui.d.ts +26 -26
- package/src/imagecaption/imagecaptionui.js +61 -61
- package/src/imagecaption/imagecaptionutils.d.ts +38 -38
- package/src/imagecaption/imagecaptionutils.js +62 -62
- package/src/imagecaption/toggleimagecaptioncommand.d.ts +66 -66
- package/src/imagecaption/toggleimagecaptioncommand.js +138 -138
- package/src/imagecaption.d.ts +26 -26
- package/src/imagecaption.js +30 -30
- package/src/imageconfig.d.ts +713 -713
- package/src/imageconfig.js +5 -5
- package/src/imageinline.d.ts +33 -33
- package/src/imageinline.js +37 -37
- package/src/imageinsert/imageinsertui.d.ts +44 -44
- package/src/imageinsert/imageinsertui.js +141 -141
- package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -61
- package/src/imageinsert/ui/imageinsertformrowview.js +54 -54
- package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -106
- package/src/imageinsert/ui/imageinsertpanelview.js +161 -161
- package/src/imageinsert/utils.d.ts +25 -25
- package/src/imageinsert/utils.js +58 -58
- package/src/imageinsert.d.ts +33 -33
- package/src/imageinsert.js +37 -37
- package/src/imageinsertviaurl.d.ts +30 -30
- package/src/imageinsertviaurl.js +34 -34
- package/src/imageresize/imageresizebuttons.d.ts +67 -67
- package/src/imageresize/imageresizebuttons.js +217 -217
- package/src/imageresize/imageresizeediting.d.ts +37 -37
- package/src/imageresize/imageresizeediting.js +114 -114
- package/src/imageresize/imageresizehandles.d.ts +30 -30
- package/src/imageresize/imageresizehandles.js +107 -107
- package/src/imageresize/resizeimagecommand.d.ts +42 -42
- package/src/imageresize/resizeimagecommand.js +61 -61
- package/src/imageresize.d.ts +27 -27
- package/src/imageresize.js +31 -31
- package/src/imagestyle/converters.d.ts +24 -24
- package/src/imagestyle/converters.js +79 -79
- package/src/imagestyle/imagestylecommand.d.ts +65 -65
- package/src/imagestyle/imagestylecommand.js +101 -101
- package/src/imagestyle/imagestyleediting.d.ts +50 -50
- package/src/imagestyle/imagestyleediting.js +108 -108
- package/src/imagestyle/imagestyleui.d.ts +56 -56
- package/src/imagestyle/imagestyleui.js +192 -192
- package/src/imagestyle/utils.d.ts +101 -101
- package/src/imagestyle/utils.js +329 -329
- package/src/imagestyle.d.ts +32 -32
- package/src/imagestyle.js +36 -36
- package/src/imagetextalternative/imagetextalternativecommand.d.ts +34 -34
- package/src/imagetextalternative/imagetextalternativecommand.js +44 -44
- package/src/imagetextalternative/imagetextalternativeediting.d.ts +28 -28
- package/src/imagetextalternative/imagetextalternativeediting.js +35 -35
- package/src/imagetextalternative/imagetextalternativeui.d.ts +68 -68
- package/src/imagetextalternative/imagetextalternativeui.js +173 -173
- package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -72
- package/src/imagetextalternative/ui/textalternativeformview.js +121 -121
- package/src/imagetextalternative.d.ts +29 -29
- package/src/imagetextalternative.js +33 -33
- package/src/imagetoolbar.d.ts +35 -35
- package/src/imagetoolbar.js +57 -57
- package/src/imageupload/imageuploadediting.d.ts +111 -111
- package/src/imageupload/imageuploadediting.js +335 -335
- package/src/imageupload/imageuploadprogress.d.ts +42 -42
- package/src/imageupload/imageuploadprogress.js +211 -211
- package/src/imageupload/imageuploadui.d.ts +23 -23
- package/src/imageupload/imageuploadui.js +57 -57
- package/src/imageupload/uploadimagecommand.d.ts +60 -60
- package/src/imageupload/uploadimagecommand.js +100 -100
- package/src/imageupload/utils.d.ts +33 -33
- package/src/imageupload/utils.js +112 -112
- package/src/imageupload.d.ts +32 -32
- package/src/imageupload.js +36 -36
- package/src/imageutils.d.ts +102 -102
- package/src/imageutils.js +248 -248
- package/src/index.d.ts +47 -47
- package/src/index.js +38 -38
- package/src/pictureediting.d.ts +88 -88
- package/src/pictureediting.js +130 -130
|
@@ -1,34 +1,34 @@
|
|
|
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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
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
|
-
/**
|
|
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
|
-
}
|
|
44
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
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
|
+
/**
|
|
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
|
+
}
|
|
44
|
+
}
|
package/src/image/ui/utils.d.ts
CHANGED
|
@@ -1,25 +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>;
|
|
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>;
|
package/src/image/ui/utils.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import { BalloonPanelView } from 'ckeditor5/src/ui';
|
|
6
|
-
/**
|
|
7
|
-
* A helper utility that positions the
|
|
8
|
-
* {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
|
|
9
|
-
* with respect to the image in the editor content, if one is selected.
|
|
10
|
-
*
|
|
11
|
-
* @param editor The editor instance.
|
|
12
|
-
*/
|
|
13
|
-
export function repositionContextualBalloon(editor) {
|
|
14
|
-
const balloon = editor.plugins.get('ContextualBalloon');
|
|
15
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
16
|
-
if (imageUtils.getClosestSelectedImageWidget(editor.editing.view.document.selection)) {
|
|
17
|
-
const position = getBalloonPositionData(editor);
|
|
18
|
-
balloon.updatePosition(position);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Returns the positioning options that control the geometry of the
|
|
23
|
-
* {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
|
|
24
|
-
* to the selected element in the editor content.
|
|
25
|
-
*
|
|
26
|
-
* @param editor The editor instance.
|
|
27
|
-
*/
|
|
28
|
-
export function getBalloonPositionData(editor) {
|
|
29
|
-
const editingView = editor.editing.view;
|
|
30
|
-
const defaultPositions = BalloonPanelView.defaultPositions;
|
|
31
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
32
|
-
return {
|
|
33
|
-
target: editingView.domConverter.mapViewToDom(imageUtils.getClosestSelectedImageWidget(editingView.document.selection)),
|
|
34
|
-
positions: [
|
|
35
|
-
defaultPositions.northArrowSouth,
|
|
36
|
-
defaultPositions.northArrowSouthWest,
|
|
37
|
-
defaultPositions.northArrowSouthEast,
|
|
38
|
-
defaultPositions.southArrowNorth,
|
|
39
|
-
defaultPositions.southArrowNorthWest,
|
|
40
|
-
defaultPositions.southArrowNorthEast,
|
|
41
|
-
defaultPositions.viewportStickyNorth
|
|
42
|
-
]
|
|
43
|
-
};
|
|
44
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { BalloonPanelView } from 'ckeditor5/src/ui';
|
|
6
|
+
/**
|
|
7
|
+
* A helper utility that positions the
|
|
8
|
+
* {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
|
|
9
|
+
* with respect to the image in the editor content, if one is selected.
|
|
10
|
+
*
|
|
11
|
+
* @param editor The editor instance.
|
|
12
|
+
*/
|
|
13
|
+
export function repositionContextualBalloon(editor) {
|
|
14
|
+
const balloon = editor.plugins.get('ContextualBalloon');
|
|
15
|
+
const imageUtils = editor.plugins.get('ImageUtils');
|
|
16
|
+
if (imageUtils.getClosestSelectedImageWidget(editor.editing.view.document.selection)) {
|
|
17
|
+
const position = getBalloonPositionData(editor);
|
|
18
|
+
balloon.updatePosition(position);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the positioning options that control the geometry of the
|
|
23
|
+
* {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
|
|
24
|
+
* to the selected element in the editor content.
|
|
25
|
+
*
|
|
26
|
+
* @param editor The editor instance.
|
|
27
|
+
*/
|
|
28
|
+
export function getBalloonPositionData(editor) {
|
|
29
|
+
const editingView = editor.editing.view;
|
|
30
|
+
const defaultPositions = BalloonPanelView.defaultPositions;
|
|
31
|
+
const imageUtils = editor.plugins.get('ImageUtils');
|
|
32
|
+
return {
|
|
33
|
+
target: editingView.domConverter.mapViewToDom(imageUtils.getClosestSelectedImageWidget(editingView.document.selection)),
|
|
34
|
+
positions: [
|
|
35
|
+
defaultPositions.northArrowSouth,
|
|
36
|
+
defaultPositions.northArrowSouthWest,
|
|
37
|
+
defaultPositions.northArrowSouthEast,
|
|
38
|
+
defaultPositions.southArrowNorth,
|
|
39
|
+
defaultPositions.southArrowNorthWest,
|
|
40
|
+
defaultPositions.southArrowNorthEast,
|
|
41
|
+
defaultPositions.viewportStickyNorth
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
}
|
package/src/image/utils.d.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
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/utils
|
|
7
|
-
*/
|
|
8
|
-
import type { DocumentSelection, MatcherPattern, Schema, Selection, ViewContainerElement, DowncastWriter } from 'ckeditor5/src/engine';
|
|
9
|
-
import type { Editor } from 'ckeditor5/src/core';
|
|
10
|
-
/**
|
|
11
|
-
* Creates a view element representing the inline image.
|
|
12
|
-
*
|
|
13
|
-
* ```html
|
|
14
|
-
* <span class="image-inline"><img></img></span>
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* Note that `alt` and `src` attributes are converted separately, so they are not included.
|
|
18
|
-
*
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
export declare function createInlineImageViewElement(writer: DowncastWriter): ViewContainerElement;
|
|
22
|
-
/**
|
|
23
|
-
* Creates a view element representing the block image.
|
|
24
|
-
*
|
|
25
|
-
* ```html
|
|
26
|
-
* <figure class="image"><img></img></figure>
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* Note that `alt` and `src` attributes are converted separately, so they are not included.
|
|
30
|
-
*
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
export declare function createBlockImageViewElement(writer: DowncastWriter): ViewContainerElement;
|
|
34
|
-
/**
|
|
35
|
-
* A function returning a `MatcherPattern` for a particular type of View images.
|
|
36
|
-
*
|
|
37
|
-
* @internal
|
|
38
|
-
* @param matchImageType The type of created image.
|
|
39
|
-
*/
|
|
40
|
-
export declare function getImgViewElementMatcher(editor: Editor, matchImageType: 'imageBlock' | 'imageInline'): MatcherPattern;
|
|
41
|
-
/**
|
|
42
|
-
* Considering the current model selection, it returns the name of the model image element
|
|
43
|
-
* (`'imageBlock'` or `'imageInline'`) that will make most sense from the UX perspective if a new
|
|
44
|
-
* image was inserted (also: uploaded, dropped, pasted) at that selection.
|
|
45
|
-
*
|
|
46
|
-
* The assumption is that inserting images into empty blocks or on other block widgets should
|
|
47
|
-
* produce block images. Inline images should be inserted in other cases, e.g. in paragraphs
|
|
48
|
-
* that already contain some text.
|
|
49
|
-
*
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
|
-
export declare function determineImageTypeForInsertionAtSelection(schema: Schema, selection: Selection | DocumentSelection): 'imageBlock' | 'imageInline';
|
|
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/utils
|
|
7
|
+
*/
|
|
8
|
+
import type { DocumentSelection, MatcherPattern, Schema, Selection, ViewContainerElement, DowncastWriter } from 'ckeditor5/src/engine';
|
|
9
|
+
import type { Editor } from 'ckeditor5/src/core';
|
|
10
|
+
/**
|
|
11
|
+
* Creates a view element representing the inline image.
|
|
12
|
+
*
|
|
13
|
+
* ```html
|
|
14
|
+
* <span class="image-inline"><img></img></span>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Note that `alt` and `src` attributes are converted separately, so they are not included.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export declare function createInlineImageViewElement(writer: DowncastWriter): ViewContainerElement;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a view element representing the block image.
|
|
24
|
+
*
|
|
25
|
+
* ```html
|
|
26
|
+
* <figure class="image"><img></img></figure>
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Note that `alt` and `src` attributes are converted separately, so they are not included.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare function createBlockImageViewElement(writer: DowncastWriter): ViewContainerElement;
|
|
34
|
+
/**
|
|
35
|
+
* A function returning a `MatcherPattern` for a particular type of View images.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
* @param matchImageType The type of created image.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getImgViewElementMatcher(editor: Editor, matchImageType: 'imageBlock' | 'imageInline'): MatcherPattern;
|
|
41
|
+
/**
|
|
42
|
+
* Considering the current model selection, it returns the name of the model image element
|
|
43
|
+
* (`'imageBlock'` or `'imageInline'`) that will make most sense from the UX perspective if a new
|
|
44
|
+
* image was inserted (also: uploaded, dropped, pasted) at that selection.
|
|
45
|
+
*
|
|
46
|
+
* The assumption is that inserting images into empty blocks or on other block widgets should
|
|
47
|
+
* produce block images. Inline images should be inserted in other cases, e.g. in paragraphs
|
|
48
|
+
* that already contain some text.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export declare function determineImageTypeForInsertionAtSelection(schema: Schema, selection: Selection | DocumentSelection): 'imageBlock' | 'imageInline';
|
package/src/image/utils.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
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 { first } from 'ckeditor5/src/utils';
|
|
6
|
-
/**
|
|
7
|
-
* Creates a view element representing the inline image.
|
|
8
|
-
*
|
|
9
|
-
* ```html
|
|
10
|
-
* <span class="image-inline"><img></img></span>
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Note that `alt` and `src` attributes are converted separately, so they are not included.
|
|
14
|
-
*
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export function createInlineImageViewElement(writer) {
|
|
18
|
-
return writer.createContainerElement('span', { class: 'image-inline' }, writer.createEmptyElement('img'));
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Creates a view element representing the block image.
|
|
22
|
-
*
|
|
23
|
-
* ```html
|
|
24
|
-
* <figure class="image"><img></img></figure>
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* Note that `alt` and `src` attributes are converted separately, so they are not included.
|
|
28
|
-
*
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
export function createBlockImageViewElement(writer) {
|
|
32
|
-
return writer.createContainerElement('figure', { class: 'image' }, [
|
|
33
|
-
writer.createEmptyElement('img'),
|
|
34
|
-
writer.createSlot('children')
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* A function returning a `MatcherPattern` for a particular type of View images.
|
|
39
|
-
*
|
|
40
|
-
* @internal
|
|
41
|
-
* @param matchImageType The type of created image.
|
|
42
|
-
*/
|
|
43
|
-
export function getImgViewElementMatcher(editor, matchImageType) {
|
|
44
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
45
|
-
const areBothImagePluginsLoaded = editor.plugins.has('ImageInlineEditing') && editor.plugins.has('ImageBlockEditing');
|
|
46
|
-
return element => {
|
|
47
|
-
// Check if the matched view element is an <img>.
|
|
48
|
-
if (!imageUtils.isInlineImageView(element)) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
// If just one of the plugins is loaded (block or inline), it will match all kinds of images.
|
|
52
|
-
if (!areBothImagePluginsLoaded) {
|
|
53
|
-
return getPositiveMatchPattern(element);
|
|
54
|
-
}
|
|
55
|
-
// The <img> can be standalone, wrapped in <figure>...</figure> (ImageBlock plugin) or
|
|
56
|
-
// wrapped in <figure><a>...</a></figure> (LinkImage plugin).
|
|
57
|
-
const imageType = element.getStyle('display') == 'block' || element.findAncestor(imageUtils.isBlockImageView) ?
|
|
58
|
-
'imageBlock' :
|
|
59
|
-
'imageInline';
|
|
60
|
-
if (imageType !== matchImageType) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
return getPositiveMatchPattern(element);
|
|
64
|
-
};
|
|
65
|
-
function getPositiveMatchPattern(element) {
|
|
66
|
-
const pattern = {
|
|
67
|
-
name: true
|
|
68
|
-
};
|
|
69
|
-
// This will trigger src consumption (See https://github.com/ckeditor/ckeditor5/issues/11530).
|
|
70
|
-
if (element.hasAttribute('src')) {
|
|
71
|
-
pattern.attributes = ['src'];
|
|
72
|
-
}
|
|
73
|
-
return pattern;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Considering the current model selection, it returns the name of the model image element
|
|
78
|
-
* (`'imageBlock'` or `'imageInline'`) that will make most sense from the UX perspective if a new
|
|
79
|
-
* image was inserted (also: uploaded, dropped, pasted) at that selection.
|
|
80
|
-
*
|
|
81
|
-
* The assumption is that inserting images into empty blocks or on other block widgets should
|
|
82
|
-
* produce block images. Inline images should be inserted in other cases, e.g. in paragraphs
|
|
83
|
-
* that already contain some text.
|
|
84
|
-
*
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
export function determineImageTypeForInsertionAtSelection(schema, selection) {
|
|
88
|
-
const firstBlock = first(selection.getSelectedBlocks());
|
|
89
|
-
// Insert a block image if the selection is not in/on block elements or it's on a block widget.
|
|
90
|
-
if (!firstBlock || schema.isObject(firstBlock)) {
|
|
91
|
-
return 'imageBlock';
|
|
92
|
-
}
|
|
93
|
-
// A block image should also be inserted into an empty block element
|
|
94
|
-
// (that is not an empty list item so the list won't get split).
|
|
95
|
-
if (firstBlock.isEmpty && firstBlock.name != 'listItem') {
|
|
96
|
-
return 'imageBlock';
|
|
97
|
-
}
|
|
98
|
-
// Otherwise insert an inline image.
|
|
99
|
-
return 'imageInline';
|
|
100
|
-
}
|
|
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 { first } from 'ckeditor5/src/utils';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a view element representing the inline image.
|
|
8
|
+
*
|
|
9
|
+
* ```html
|
|
10
|
+
* <span class="image-inline"><img></img></span>
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Note that `alt` and `src` attributes are converted separately, so they are not included.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export function createInlineImageViewElement(writer) {
|
|
18
|
+
return writer.createContainerElement('span', { class: 'image-inline' }, writer.createEmptyElement('img'));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a view element representing the block image.
|
|
22
|
+
*
|
|
23
|
+
* ```html
|
|
24
|
+
* <figure class="image"><img></img></figure>
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Note that `alt` and `src` attributes are converted separately, so they are not included.
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export function createBlockImageViewElement(writer) {
|
|
32
|
+
return writer.createContainerElement('figure', { class: 'image' }, [
|
|
33
|
+
writer.createEmptyElement('img'),
|
|
34
|
+
writer.createSlot('children')
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A function returning a `MatcherPattern` for a particular type of View images.
|
|
39
|
+
*
|
|
40
|
+
* @internal
|
|
41
|
+
* @param matchImageType The type of created image.
|
|
42
|
+
*/
|
|
43
|
+
export function getImgViewElementMatcher(editor, matchImageType) {
|
|
44
|
+
const imageUtils = editor.plugins.get('ImageUtils');
|
|
45
|
+
const areBothImagePluginsLoaded = editor.plugins.has('ImageInlineEditing') && editor.plugins.has('ImageBlockEditing');
|
|
46
|
+
return element => {
|
|
47
|
+
// Check if the matched view element is an <img>.
|
|
48
|
+
if (!imageUtils.isInlineImageView(element)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
// If just one of the plugins is loaded (block or inline), it will match all kinds of images.
|
|
52
|
+
if (!areBothImagePluginsLoaded) {
|
|
53
|
+
return getPositiveMatchPattern(element);
|
|
54
|
+
}
|
|
55
|
+
// The <img> can be standalone, wrapped in <figure>...</figure> (ImageBlock plugin) or
|
|
56
|
+
// wrapped in <figure><a>...</a></figure> (LinkImage plugin).
|
|
57
|
+
const imageType = element.getStyle('display') == 'block' || element.findAncestor(imageUtils.isBlockImageView) ?
|
|
58
|
+
'imageBlock' :
|
|
59
|
+
'imageInline';
|
|
60
|
+
if (imageType !== matchImageType) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return getPositiveMatchPattern(element);
|
|
64
|
+
};
|
|
65
|
+
function getPositiveMatchPattern(element) {
|
|
66
|
+
const pattern = {
|
|
67
|
+
name: true
|
|
68
|
+
};
|
|
69
|
+
// This will trigger src consumption (See https://github.com/ckeditor/ckeditor5/issues/11530).
|
|
70
|
+
if (element.hasAttribute('src')) {
|
|
71
|
+
pattern.attributes = ['src'];
|
|
72
|
+
}
|
|
73
|
+
return pattern;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Considering the current model selection, it returns the name of the model image element
|
|
78
|
+
* (`'imageBlock'` or `'imageInline'`) that will make most sense from the UX perspective if a new
|
|
79
|
+
* image was inserted (also: uploaded, dropped, pasted) at that selection.
|
|
80
|
+
*
|
|
81
|
+
* The assumption is that inserting images into empty blocks or on other block widgets should
|
|
82
|
+
* produce block images. Inline images should be inserted in other cases, e.g. in paragraphs
|
|
83
|
+
* that already contain some text.
|
|
84
|
+
*
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
export function determineImageTypeForInsertionAtSelection(schema, selection) {
|
|
88
|
+
const firstBlock = first(selection.getSelectedBlocks());
|
|
89
|
+
// Insert a block image if the selection is not in/on block elements or it's on a block widget.
|
|
90
|
+
if (!firstBlock || schema.isObject(firstBlock)) {
|
|
91
|
+
return 'imageBlock';
|
|
92
|
+
}
|
|
93
|
+
// A block image should also be inserted into an empty block element
|
|
94
|
+
// (that is not an empty list item so the list won't get split).
|
|
95
|
+
if (firstBlock.isEmpty && firstBlock.name != 'listItem') {
|
|
96
|
+
return 'imageBlock';
|
|
97
|
+
}
|
|
98
|
+
// Otherwise insert an inline image.
|
|
99
|
+
return 'imageInline';
|
|
100
|
+
}
|