@ckeditor/ckeditor5-image 32.0.0 → 33.0.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 +2 -2
- package/build/image.js.map +1 -0
- package/build/translations/el.js +1 -1
- package/build/translations/es.js +1 -1
- package/lang/translations/el.po +22 -22
- package/lang/translations/es.po +7 -7
- package/package.json +32 -31
- package/src/image/converters.js +6 -7
- package/src/image/imageblockediting.js +5 -5
- package/src/image/imageinlineediting.js +3 -3
- package/src/image/utils.js +22 -16
- package/src/imagecaption/imagecaptionediting.js +6 -32
- package/src/imagecaption/imagecaptionui.js +4 -6
- package/src/imagecaption/imagecaptionutils.js +89 -0
- package/src/imagecaption/toggleimagecaptioncommand.js +6 -7
- package/src/imagestyle/utils.js +64 -48
- package/src/index.js +1 -0
- package/src/imagecaption/utils.js +0 -63
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
import { Command } from 'ckeditor5/src/core';
|
|
11
11
|
|
|
12
12
|
import ImageBlockEditing from '../image/imageblockediting';
|
|
13
|
-
import { getCaptionFromImageModelElement, getCaptionFromModelSelection } from './utils';
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* The toggle image caption command.
|
|
@@ -41,7 +40,7 @@ export default class ToggleImageCaptionCommand extends Command {
|
|
|
41
40
|
*/
|
|
42
41
|
refresh() {
|
|
43
42
|
const editor = this.editor;
|
|
44
|
-
const
|
|
43
|
+
const imageCaptionUtils = editor.plugins.get( 'ImageCaptionUtils' );
|
|
45
44
|
|
|
46
45
|
// Only block images can get captions.
|
|
47
46
|
if ( !editor.plugins.has( ImageBlockEditing ) ) {
|
|
@@ -55,7 +54,7 @@ export default class ToggleImageCaptionCommand extends Command {
|
|
|
55
54
|
const selectedElement = selection.getSelectedElement();
|
|
56
55
|
|
|
57
56
|
if ( !selectedElement ) {
|
|
58
|
-
const ancestorCaptionElement = getCaptionFromModelSelection(
|
|
57
|
+
const ancestorCaptionElement = imageCaptionUtils.getCaptionFromModelSelection( selection );
|
|
59
58
|
|
|
60
59
|
this.isEnabled = !!ancestorCaptionElement;
|
|
61
60
|
this.value = !!ancestorCaptionElement;
|
|
@@ -70,7 +69,7 @@ export default class ToggleImageCaptionCommand extends Command {
|
|
|
70
69
|
if ( !this.isEnabled ) {
|
|
71
70
|
this.value = false;
|
|
72
71
|
} else {
|
|
73
|
-
this.value = !!getCaptionFromImageModelElement( selectedElement );
|
|
72
|
+
this.value = !!imageCaptionUtils.getCaptionFromImageModelElement( selectedElement );
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
|
|
@@ -145,14 +144,14 @@ export default class ToggleImageCaptionCommand extends Command {
|
|
|
145
144
|
const editor = this.editor;
|
|
146
145
|
const selection = editor.model.document.selection;
|
|
147
146
|
const imageCaptionEditing = editor.plugins.get( 'ImageCaptionEditing' );
|
|
148
|
-
const
|
|
147
|
+
const imageCaptionUtils = editor.plugins.get( 'ImageCaptionUtils' );
|
|
149
148
|
let selectedImage = selection.getSelectedElement();
|
|
150
149
|
let captionElement;
|
|
151
150
|
|
|
152
151
|
if ( selectedImage ) {
|
|
153
|
-
captionElement = getCaptionFromImageModelElement( selectedImage );
|
|
152
|
+
captionElement = imageCaptionUtils.getCaptionFromImageModelElement( selectedImage );
|
|
154
153
|
} else {
|
|
155
|
-
captionElement = getCaptionFromModelSelection(
|
|
154
|
+
captionElement = imageCaptionUtils.getCaptionFromModelSelection( selection );
|
|
156
155
|
selectedImage = captionElement.parent;
|
|
157
156
|
}
|
|
158
157
|
|
package/src/imagestyle/utils.js
CHANGED
|
@@ -40,75 +40,91 @@ const {
|
|
|
40
40
|
*/
|
|
41
41
|
const DEFAULT_OPTIONS = {
|
|
42
42
|
// This style represents an image placed in the line of text.
|
|
43
|
-
inline
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
get inline() {
|
|
44
|
+
return {
|
|
45
|
+
name: 'inline',
|
|
46
|
+
title: 'In line',
|
|
47
|
+
icon: objectInline,
|
|
48
|
+
modelElements: [ 'imageInline' ],
|
|
49
|
+
isDefault: true
|
|
50
|
+
};
|
|
49
51
|
},
|
|
50
52
|
|
|
51
53
|
// This style represents an image aligned to the left and wrapped with text.
|
|
52
|
-
alignLeft
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
get alignLeft() {
|
|
55
|
+
return {
|
|
56
|
+
name: 'alignLeft',
|
|
57
|
+
title: 'Left aligned image',
|
|
58
|
+
icon: objectLeft,
|
|
59
|
+
modelElements: [ 'imageBlock', 'imageInline' ],
|
|
60
|
+
className: 'image-style-align-left'
|
|
61
|
+
};
|
|
58
62
|
},
|
|
59
63
|
|
|
60
64
|
// This style represents an image aligned to the left.
|
|
61
|
-
alignBlockLeft
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
get alignBlockLeft() {
|
|
66
|
+
return {
|
|
67
|
+
name: 'alignBlockLeft',
|
|
68
|
+
title: 'Left aligned image',
|
|
69
|
+
icon: objectBlockLeft,
|
|
70
|
+
modelElements: [ 'imageBlock' ],
|
|
71
|
+
className: 'image-style-block-align-left'
|
|
72
|
+
};
|
|
67
73
|
},
|
|
68
74
|
|
|
69
75
|
// This style represents a centered image.
|
|
70
|
-
alignCenter
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
get alignCenter() {
|
|
77
|
+
return {
|
|
78
|
+
name: 'alignCenter',
|
|
79
|
+
title: 'Centered image',
|
|
80
|
+
icon: objectCenter,
|
|
81
|
+
modelElements: [ 'imageBlock' ],
|
|
82
|
+
className: 'image-style-align-center'
|
|
83
|
+
};
|
|
76
84
|
},
|
|
77
85
|
|
|
78
86
|
// This style represents an image aligned to the right and wrapped with text.
|
|
79
|
-
alignRight
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
get alignRight() {
|
|
88
|
+
return {
|
|
89
|
+
name: 'alignRight',
|
|
90
|
+
title: 'Right aligned image',
|
|
91
|
+
icon: objectRight,
|
|
92
|
+
modelElements: [ 'imageBlock', 'imageInline' ],
|
|
93
|
+
className: 'image-style-align-right'
|
|
94
|
+
};
|
|
85
95
|
},
|
|
86
96
|
|
|
87
97
|
// This style represents an image aligned to the right.
|
|
88
|
-
alignBlockRight
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
98
|
+
get alignBlockRight() {
|
|
99
|
+
return {
|
|
100
|
+
name: 'alignBlockRight',
|
|
101
|
+
title: 'Right aligned image',
|
|
102
|
+
icon: objectBlockRight,
|
|
103
|
+
modelElements: [ 'imageBlock' ],
|
|
104
|
+
className: 'image-style-block-align-right'
|
|
105
|
+
};
|
|
94
106
|
},
|
|
95
107
|
|
|
96
108
|
// This option is equal to the situation when no style is applied.
|
|
97
|
-
block
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
109
|
+
get block() {
|
|
110
|
+
return {
|
|
111
|
+
name: 'block',
|
|
112
|
+
title: 'Centered image',
|
|
113
|
+
icon: objectCenter,
|
|
114
|
+
modelElements: [ 'imageBlock' ],
|
|
115
|
+
isDefault: true
|
|
116
|
+
};
|
|
103
117
|
},
|
|
104
118
|
|
|
105
119
|
// This represents a side image.
|
|
106
|
-
side
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
get side() {
|
|
121
|
+
return {
|
|
122
|
+
name: 'side',
|
|
123
|
+
title: 'Side image',
|
|
124
|
+
icon: objectRight,
|
|
125
|
+
modelElements: [ 'imageBlock' ],
|
|
126
|
+
className: 'image-style-side'
|
|
127
|
+
};
|
|
112
128
|
}
|
|
113
129
|
};
|
|
114
130
|
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
export { default as AutoImage } from './autoimage';
|
|
11
11
|
export { default as Image } from './image';
|
|
12
12
|
export { default as ImageEditing } from './image/imageediting';
|
|
13
|
+
export { default as ImageCaptionUtils } from './imagecaption/imagecaptionutils';
|
|
13
14
|
export { default as ImageCaption } from './imagecaption';
|
|
14
15
|
export { default as ImageCaptionEditing } from './imagecaption/imagecaptionediting';
|
|
15
16
|
export { default as ImageInsert } from './imageinsert';
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2022, 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
|
-
/**
|
|
7
|
-
* @module image/imagecaption/utils
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Returns the caption model element from a given image element. Returns `null` if no caption is found.
|
|
12
|
-
*
|
|
13
|
-
* @param {module:engine/model/element~Element} imageModelElement
|
|
14
|
-
* @returns {module:engine/model/element~Element|null}
|
|
15
|
-
*/
|
|
16
|
-
export function getCaptionFromImageModelElement( imageModelElement ) {
|
|
17
|
-
for ( const node of imageModelElement.getChildren() ) {
|
|
18
|
-
if ( !!node && node.is( 'element', 'caption' ) ) {
|
|
19
|
-
return node;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Returns the caption model element for a model selection. Returns `null` if the selection has no caption element ancestor.
|
|
28
|
-
*
|
|
29
|
-
* @param {module:image/imageutils~ImageUtils} imageUtils
|
|
30
|
-
* @param {module:engine/model/selection~Selection} selection
|
|
31
|
-
* @returns {module:engine/model/element~Element|null}
|
|
32
|
-
*/
|
|
33
|
-
export function getCaptionFromModelSelection( imageUtils, selection ) {
|
|
34
|
-
const captionElement = selection.getFirstPosition().findAncestor( 'caption' );
|
|
35
|
-
|
|
36
|
-
if ( !captionElement ) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if ( imageUtils.isBlockImage( captionElement.parent ) ) {
|
|
41
|
-
return captionElement;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* {@link module:engine/view/matcher~Matcher} pattern. Checks if a given element is a `<figcaption>` element that is placed
|
|
49
|
-
* inside the image `<figure>` element.
|
|
50
|
-
*
|
|
51
|
-
* @param {module:image/imageutils~ImageUtils} imageUtils
|
|
52
|
-
* @param {module:engine/view/element~Element} element
|
|
53
|
-
* @returns {Object|null} Returns the object accepted by {@link module:engine/view/matcher~Matcher} or `null` if the element
|
|
54
|
-
* cannot be matched.
|
|
55
|
-
*/
|
|
56
|
-
export function matchImageCaptionViewElement( imageUtils, element ) {
|
|
57
|
-
// Convert only captions for images.
|
|
58
|
-
if ( element.name == 'figcaption' && imageUtils.isBlockImageView( element.parent ) ) {
|
|
59
|
-
return { name: true };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return null;
|
|
63
|
-
}
|