@ckeditor/ckeditor5-image 36.0.1 → 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
@@ -2,53 +2,43 @@
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/image/ui/utils
8
- */
9
-
10
5
  import { BalloonPanelView } from 'ckeditor5/src/ui';
11
-
12
6
  /**
13
7
  * A helper utility that positions the
14
8
  * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
15
9
  * with respect to the image in the editor content, if one is selected.
16
10
  *
17
- * @param {module:core/editor/editor~Editor} editor The editor instance.
11
+ * @param editor The editor instance.
18
12
  */
19
- export function repositionContextualBalloon( editor ) {
20
- const balloon = editor.plugins.get( 'ContextualBalloon' );
21
-
22
- if ( editor.plugins.get( 'ImageUtils' ).getClosestSelectedImageWidget( editor.editing.view.document.selection ) ) {
23
- const position = getBalloonPositionData( editor );
24
-
25
- balloon.updatePosition( position );
26
- }
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
+ }
27
20
  }
28
-
29
21
  /**
30
22
  * Returns the positioning options that control the geometry of the
31
23
  * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
32
24
  * to the selected element in the editor content.
33
25
  *
34
- * @param {module:core/editor/editor~Editor} editor The editor instance.
35
- * @returns {module:utils/dom/position~Options}
26
+ * @param editor The editor instance.
36
27
  */
37
- export function getBalloonPositionData( editor ) {
38
- const editingView = editor.editing.view;
39
- const defaultPositions = BalloonPanelView.defaultPositions;
40
- const imageUtils = editor.plugins.get( 'ImageUtils' );
41
-
42
- return {
43
- target: editingView.domConverter.mapViewToDom( imageUtils.getClosestSelectedImageWidget( editingView.document.selection ) ),
44
- positions: [
45
- defaultPositions.northArrowSouth,
46
- defaultPositions.northArrowSouthWest,
47
- defaultPositions.northArrowSouthEast,
48
- defaultPositions.southArrowNorth,
49
- defaultPositions.southArrowNorthWest,
50
- defaultPositions.southArrowNorthEast,
51
- defaultPositions.viewportStickyNorth
52
- ]
53
- };
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
+ };
54
44
  }
@@ -0,0 +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';
@@ -2,98 +2,77 @@
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/image/utils
8
- */
9
-
10
5
  import { first } from 'ckeditor5/src/utils';
11
-
12
6
  /**
13
7
  * Creates a view element representing the inline image.
14
8
  *
15
- * <span class="image-inline"><img></img></span>
9
+ * ```html
10
+ * <span class="image-inline"><img></img></span>
11
+ * ```
16
12
  *
17
13
  * Note that `alt` and `src` attributes are converted separately, so they are not included.
18
14
  *
19
- * @protected
20
- * @param {module:engine/view/downcastwriter~DowncastWriter} writer
21
- * @returns {module:engine/view/containerelement~ContainerElement}
15
+ * @internal
22
16
  */
23
- export function createInlineImageViewElement( writer ) {
24
- return writer.createContainerElement( 'span', { class: 'image-inline' },
25
- writer.createEmptyElement( 'img' )
26
- );
17
+ export function createInlineImageViewElement(writer) {
18
+ return writer.createContainerElement('span', { class: 'image-inline' }, writer.createEmptyElement('img'));
27
19
  }
28
-
29
20
  /**
30
21
  * Creates a view element representing the block image.
31
22
  *
32
- * <figure class="image"><img></img></figure>
23
+ * ```html
24
+ * <figure class="image"><img></img></figure>
25
+ * ```
33
26
  *
34
27
  * Note that `alt` and `src` attributes are converted separately, so they are not included.
35
28
  *
36
- * @protected
37
- * @param {module:engine/view/downcastwriter~DowncastWriter} writer
38
- * @returns {module:engine/view/containerelement~ContainerElement}
29
+ * @internal
39
30
  */
40
- export function createBlockImageViewElement( writer ) {
41
- return writer.createContainerElement( 'figure', { class: 'image' }, [
42
- writer.createEmptyElement( 'img' ),
43
- writer.createSlot()
44
- ] );
31
+ export function createBlockImageViewElement(writer) {
32
+ return writer.createContainerElement('figure', { class: 'image' }, [
33
+ writer.createEmptyElement('img'),
34
+ writer.createSlot('children')
35
+ ]);
45
36
  }
46
-
47
37
  /**
48
38
  * A function returning a `MatcherPattern` for a particular type of View images.
49
39
  *
50
- * @protected
51
- * @param {module:core/editor/editor~Editor} editor
52
- * @param {'imageBlock'|'imageInline'} matchImageType The type of created image.
53
- * @returns {module:engine/view/matcher~MatcherPattern}
40
+ * @internal
41
+ * @param matchImageType The type of created image.
54
42
  */
55
- export function getImgViewElementMatcher( editor, matchImageType ) {
56
- const imageUtils = editor.plugins.get( 'ImageUtils' );
57
- const areBothImagePluginsLoaded = editor.plugins.has( 'ImageInlineEditing' ) && editor.plugins.has( 'ImageBlockEditing' );
58
-
59
- return element => {
60
- // Check if the matched view element is an <img>.
61
- if ( !imageUtils.isInlineImageView( element ) ) {
62
- return null;
63
- }
64
-
65
- // If just one of the plugins is loaded (block or inline), it will match all kinds of images.
66
- if ( !areBothImagePluginsLoaded ) {
67
- return getPositiveMatchPattern( element );
68
- }
69
-
70
- // The <img> can be standalone, wrapped in <figure>...</figure> (ImageBlock plugin) or
71
- // wrapped in <figure><a>...</a></figure> (LinkImage plugin).
72
- const imageType = element.getStyle( 'display' ) == 'block' || element.findAncestor( imageUtils.isBlockImageView ) ?
73
- 'imageBlock' :
74
- 'imageInline';
75
-
76
- if ( imageType !== matchImageType ) {
77
- return null;
78
- }
79
-
80
- return getPositiveMatchPattern( element );
81
- };
82
-
83
- function getPositiveMatchPattern( element ) {
84
- const pattern = {
85
- name: true
86
- };
87
-
88
- // This will trigger src consumption (See https://github.com/ckeditor/ckeditor5/issues/11530).
89
- if ( element.hasAttribute( 'src' ) ) {
90
- pattern.attributes = [ 'src' ];
91
- }
92
-
93
- return pattern;
94
- }
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
+ }
95
75
  }
96
-
97
76
  /**
98
77
  * Considering the current model selection, it returns the name of the model image element
99
78
  * (`'imageBlock'` or `'imageInline'`) that will make most sense from the UX perspective if a new
@@ -103,25 +82,19 @@ export function getImgViewElementMatcher( editor, matchImageType ) {
103
82
  * produce block images. Inline images should be inserted in other cases, e.g. in paragraphs
104
83
  * that already contain some text.
105
84
  *
106
- * @protected
107
- * @param {module:engine/model/schema~Schema} schema
108
- * @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
109
- * @returns {'imageBlock'|'imageInline'}
85
+ * @internal
110
86
  */
111
- export function determineImageTypeForInsertionAtSelection( schema, selection ) {
112
- const firstBlock = first( selection.getSelectedBlocks() );
113
-
114
- // Insert a block image if the selection is not in/on block elements or it's on a block widget.
115
- if ( !firstBlock || schema.isObject( firstBlock ) ) {
116
- return 'imageBlock';
117
- }
118
-
119
- // A block image should also be inserted into an empty block element
120
- // (that is not an empty list item so the list won't get split).
121
- if ( firstBlock.isEmpty && firstBlock.name != 'listItem' ) {
122
- return 'imageBlock';
123
- }
124
-
125
- // Otherwise insert an inline image.
126
- return 'imageInline';
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';
127
100
  }
package/src/image.d.ts ADDED
@@ -0,0 +1,38 @@
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
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ import '../theme/image.css';
10
+ import './imageconfig';
11
+ /**
12
+ * The image plugin.
13
+ *
14
+ * For a detailed overview, check the {@glink features/images/images-overview image feature} documentation.
15
+ *
16
+ * This is a "glue" plugin which loads the following plugins:
17
+ *
18
+ * * {@link module:image/imageblock~ImageBlock},
19
+ * * {@link module:image/imageinline~ImageInline},
20
+ *
21
+ * Usually, it is used in conjunction with other plugins from this package. See the {@glink api/image package page}
22
+ * for more information.
23
+ */
24
+ export default class Image extends Plugin {
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ static get requires(): PluginDependencies;
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get pluginName(): 'Image';
33
+ }
34
+ declare module '@ckeditor/ckeditor5-core' {
35
+ interface PluginsMap {
36
+ [Image.pluginName]: Image;
37
+ }
38
+ }
package/src/image.js CHANGED
@@ -2,18 +2,14 @@
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/image
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
-
12
9
  import ImageBlock from './imageblock';
13
10
  import ImageInline from './imageinline';
14
-
15
11
  import '../theme/image.css';
16
-
12
+ import './imageconfig';
17
13
  /**
18
14
  * The image plugin.
19
15
  *
@@ -26,44 +22,18 @@ import '../theme/image.css';
26
22
  *
27
23
  * Usually, it is used in conjunction with other plugins from this package. See the {@glink api/image package page}
28
24
  * for more information.
29
- *
30
- * @extends module:core/plugin~Plugin
31
25
  */
32
26
  export default class Image extends Plugin {
33
- /**
34
- * @inheritDoc
35
- */
36
- static get requires() {
37
- return [ ImageBlock, ImageInline ];
38
- }
39
-
40
- /**
41
- * @inheritDoc
42
- */
43
- static get pluginName() {
44
- return 'Image';
45
- }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ static get requires() {
31
+ return [ImageBlock, ImageInline];
32
+ }
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ static get pluginName() {
37
+ return 'Image';
38
+ }
46
39
  }
47
-
48
- /**
49
- * The configuration of the image features. Used by the image features in the `@ckeditor/ckeditor5-image` package.
50
- *
51
- * Read more in {@link module:image/image~ImageConfig}.
52
- *
53
- * @member {module:image/image~ImageConfig} module:core/editor/editorconfig~EditorConfig#image
54
- */
55
-
56
- /**
57
- * The configuration of the image features. Used by the image features in the `@ckeditor/ckeditor5-image` package.
58
- *
59
- * ClassicEditor
60
- * .create( editorElement, {
61
- * image: ... // Image feature options.
62
- * } )
63
- * .then( ... )
64
- * .catch( ... );
65
- *
66
- * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
67
- *
68
- * @interface ImageConfig
69
- */
@@ -0,0 +1,35 @@
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/imageblock
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ import '../theme/image.css';
10
+ /**
11
+ * The image block plugin.
12
+ *
13
+ * This is a "glue" plugin which loads the following plugins:
14
+ *
15
+ * * {@link module:image/image/imageblockediting~ImageBlockEditing},
16
+ * * {@link module:image/imagetextalternative~ImageTextAlternative}.
17
+ *
18
+ * Usually, it is used in conjunction with other plugins from this package. See the {@glink api/image package page}
19
+ * for more information.
20
+ */
21
+ export default class ImageBlock extends Plugin {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get requires(): PluginDependencies;
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ static get pluginName(): 'ImageBlock';
30
+ }
31
+ declare module '@ckeditor/ckeditor5-core' {
32
+ interface PluginsMap {
33
+ [ImageBlock.pluginName]: ImageBlock;
34
+ }
35
+ }
package/src/imageblock.js CHANGED
@@ -2,19 +2,14 @@
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/imageblock
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { Widget } from 'ckeditor5/src/widget';
12
-
13
10
  import ImageTextAlternative from './imagetextalternative';
14
11
  import ImageBlockEditing from './image/imageblockediting';
15
-
16
12
  import '../theme/image.css';
17
-
18
13
  /**
19
14
  * The image block plugin.
20
15
  *
@@ -25,22 +20,18 @@ import '../theme/image.css';
25
20
  *
26
21
  * Usually, it is used in conjunction with other plugins from this package. See the {@glink api/image package page}
27
22
  * for more information.
28
- *
29
- * @extends module:core/plugin~Plugin
30
23
  */
31
24
  export default class ImageBlock extends Plugin {
32
- /**
33
- * @inheritDoc
34
- */
35
- static get requires() {
36
- return [ ImageBlockEditing, Widget, ImageTextAlternative ];
37
- }
38
-
39
- /**
40
- * @inheritDoc
41
- */
42
- static get pluginName() {
43
- return 'ImageBlock';
44
- }
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ static get requires() {
29
+ return [ImageBlockEditing, Widget, ImageTextAlternative];
30
+ }
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ static get pluginName() {
35
+ return 'ImageBlock';
36
+ }
45
37
  }
46
-
@@ -0,0 +1,92 @@
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/imagecaption/imagecaptionediting
7
+ */
8
+ import { type Editor, Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ import { Element } from 'ckeditor5/src/engine';
10
+ /**
11
+ * The image caption engine plugin. It is responsible for:
12
+ *
13
+ * * registering converters for the caption element,
14
+ * * registering converters for the caption model attribute,
15
+ * * registering the {@link module:image/imagecaption/toggleimagecaptioncommand~ToggleImageCaptionCommand `toggleImageCaption`} command.
16
+ */
17
+ export default class ImageCaptionEditing extends Plugin {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get requires(): PluginDependencies;
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get pluginName(): 'ImageCaptionEditing';
26
+ /**
27
+ * A map that keeps saved JSONified image captions and image model elements they are
28
+ * associated with.
29
+ *
30
+ * To learn more about this system, see {@link #_saveCaption}.
31
+ */
32
+ private _savedCaptionsMap;
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ constructor(editor: Editor);
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ init(): void;
41
+ /**
42
+ * Configures conversion pipelines to support upcasting and downcasting
43
+ * image captions.
44
+ */
45
+ private _setupConversion;
46
+ /**
47
+ * Integrates with {@link module:image/image/imagetypecommand~ImageTypeCommand image type commands}
48
+ * to make sure the caption is preserved when the type of an image changes so it can be restored
49
+ * in the future if the user decides they want their caption back.
50
+ */
51
+ private _setupImageTypeCommandsIntegration;
52
+ /**
53
+ * Returns the saved {@link module:engine/model/element~Element#toJSON JSONified} caption
54
+ * of an image model element.
55
+ *
56
+ * See {@link #_saveCaption}.
57
+ *
58
+ * @internal
59
+ * @param imageModelElement The model element the caption should be returned for.
60
+ * @returns The model caption element or `null` if there is none.
61
+ */
62
+ _getSavedCaption(imageModelElement: Element): Element | null;
63
+ /**
64
+ * Saves a {@link module:engine/model/element~Element#toJSON JSONified} caption for
65
+ * an image element to allow restoring it in the future.
66
+ *
67
+ * A caption is saved every time it gets hidden and/or the type of an image changes. The
68
+ * user should be able to restore it on demand.
69
+ *
70
+ * **Note**: The caption cannot be stored in the image model element attribute because,
71
+ * for instance, when the model state propagates to collaborators, the attribute would get
72
+ * lost (mainly because it does not convert to anything when the caption is hidden) and
73
+ * the states of collaborators' models would de-synchronize causing numerous issues.
74
+ *
75
+ * See {@link #_getSavedCaption}.
76
+ *
77
+ * @internal
78
+ * @param imageModelElement The model element the caption is saved for.
79
+ * @param caption The caption model element to be saved.
80
+ */
81
+ _saveCaption(imageModelElement: Element, caption: Element): void;
82
+ /**
83
+ * Reconverts image caption when image alt attribute changes.
84
+ * The change of alt attribute is reflected in caption's aria-label attribute.
85
+ */
86
+ private _registerCaptionReconversion;
87
+ }
88
+ declare module '@ckeditor/ckeditor5-core' {
89
+ interface PluginsMap {
90
+ [ImageCaptionEditing.pluginName]: ImageCaptionEditing;
91
+ }
92
+ }