@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.
@@ -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 imageUtils = editor.plugins.get( 'ImageUtils' );
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( imageUtils, selection );
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 imageUtils = editor.plugins.get( 'ImageUtils' );
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( imageUtils, selection );
154
+ captionElement = imageCaptionUtils.getCaptionFromModelSelection( selection );
156
155
  selectedImage = captionElement.parent;
157
156
  }
158
157
 
@@ -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
- name: 'inline',
45
- title: 'In line',
46
- icon: objectInline,
47
- modelElements: [ 'imageInline' ],
48
- isDefault: true
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
- name: 'alignLeft',
54
- title: 'Left aligned image',
55
- icon: objectLeft,
56
- modelElements: [ 'imageBlock', 'imageInline' ],
57
- className: 'image-style-align-left'
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
- name: 'alignBlockLeft',
63
- title: 'Left aligned image',
64
- icon: objectBlockLeft,
65
- modelElements: [ 'imageBlock' ],
66
- className: 'image-style-block-align-left'
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
- name: 'alignCenter',
72
- title: 'Centered image',
73
- icon: objectCenter,
74
- modelElements: [ 'imageBlock' ],
75
- className: 'image-style-align-center'
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
- name: 'alignRight',
81
- title: 'Right aligned image',
82
- icon: objectRight,
83
- modelElements: [ 'imageBlock', 'imageInline' ],
84
- className: 'image-style-align-right'
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
- name: 'alignBlockRight',
90
- title: 'Right aligned image',
91
- icon: objectBlockRight,
92
- modelElements: [ 'imageBlock' ],
93
- className: 'image-style-block-align-right'
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
- name: 'block',
99
- title: 'Centered image',
100
- icon: objectCenter,
101
- modelElements: [ 'imageBlock' ],
102
- isDefault: true
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
- name: 'side',
108
- title: 'Side image',
109
- icon: objectRight,
110
- modelElements: [ 'imageBlock' ],
111
- className: 'image-style-side'
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
- }