@ckeditor/ckeditor5-image 36.0.1 → 37.0.0-alpha.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.
Files changed (108) hide show
  1. package/build/image.js +1 -1
  2. package/package.json +40 -35
  3. package/src/augmentation.d.ts +55 -0
  4. package/src/augmentation.js +5 -0
  5. package/src/autoimage.d.ts +48 -0
  6. package/src/autoimage.js +111 -160
  7. package/src/image/converters.d.ts +66 -0
  8. package/src/image/converters.js +200 -261
  9. package/src/image/imageblockediting.d.ts +52 -0
  10. package/src/image/imageblockediting.js +111 -155
  11. package/src/image/imageediting.d.ts +29 -0
  12. package/src/image/imageediting.js +53 -67
  13. package/src/image/imageinlineediting.d.ts +53 -0
  14. package/src/image/imageinlineediting.js +135 -180
  15. package/src/image/imageloadobserver.d.ts +44 -0
  16. package/src/image/imageloadobserver.js +28 -47
  17. package/src/image/imagetypecommand.d.ts +40 -0
  18. package/src/image/imagetypecommand.js +67 -95
  19. package/src/image/insertimagecommand.d.ts +66 -0
  20. package/src/image/insertimagecommand.js +94 -101
  21. package/src/image/replaceimagesourcecommand.d.ts +34 -0
  22. package/src/image/replaceimagesourcecommand.js +28 -33
  23. package/src/image/ui/utils.d.ts +25 -0
  24. package/src/image/ui/utils.js +25 -35
  25. package/src/image/utils.d.ts +52 -0
  26. package/src/image/utils.js +63 -90
  27. package/src/image.d.ts +32 -0
  28. package/src/image.js +12 -43
  29. package/src/imageblock.d.ts +30 -0
  30. package/src/imageblock.js +12 -21
  31. package/src/imagecaption/imagecaptionediting.d.ts +87 -0
  32. package/src/imagecaption/imagecaptionediting.js +203 -262
  33. package/src/imagecaption/imagecaptionui.d.ts +25 -0
  34. package/src/imagecaption/imagecaptionui.js +46 -63
  35. package/src/imagecaption/imagecaptionutils.d.ts +37 -0
  36. package/src/imagecaption/imagecaptionutils.js +51 -78
  37. package/src/imagecaption/toggleimagecaptioncommand.d.ts +66 -0
  38. package/src/imagecaption/toggleimagecaptioncommand.js +112 -138
  39. package/src/imagecaption.d.ts +24 -0
  40. package/src/imagecaption.js +12 -19
  41. package/src/imageconfig.d.ts +713 -0
  42. package/src/imageconfig.js +5 -0
  43. package/src/imageinline.d.ts +30 -0
  44. package/src/imageinline.js +12 -21
  45. package/src/imageinsert/imageinsertui.d.ts +44 -0
  46. package/src/imageinsert/imageinsertui.js +120 -158
  47. package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -0
  48. package/src/imageinsert/ui/imageinsertformrowview.js +37 -86
  49. package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -0
  50. package/src/imageinsert/ui/imageinsertpanelview.js +148 -258
  51. package/src/imageinsert/utils.d.ts +25 -0
  52. package/src/imageinsert/utils.js +41 -58
  53. package/src/imageinsert.d.ts +30 -0
  54. package/src/imageinsert.js +13 -84
  55. package/src/imageinsertviaurl.d.ts +29 -0
  56. package/src/imageinsertviaurl.js +12 -18
  57. package/src/imageresize/imageresizebuttons.d.ts +66 -0
  58. package/src/imageresize/imageresizebuttons.js +190 -255
  59. package/src/imageresize/imageresizeediting.d.ts +36 -0
  60. package/src/imageresize/imageresizeediting.js +99 -125
  61. package/src/imageresize/imageresizehandles.d.ts +29 -0
  62. package/src/imageresize/imageresizehandles.js +90 -123
  63. package/src/imageresize/resizeimagecommand.d.ts +42 -0
  64. package/src/imageresize/resizeimagecommand.js +48 -55
  65. package/src/imageresize.d.ts +24 -0
  66. package/src/imageresize.js +12 -209
  67. package/src/imagestyle/converters.d.ts +24 -0
  68. package/src/imagestyle/converters.js +60 -78
  69. package/src/imagestyle/imagestylecommand.d.ts +65 -0
  70. package/src/imagestyle/imagestylecommand.js +88 -124
  71. package/src/imagestyle/imagestyleediting.d.ts +49 -0
  72. package/src/imagestyle/imagestyleediting.js +90 -137
  73. package/src/imagestyle/imagestyleui.d.ts +55 -0
  74. package/src/imagestyle/imagestyleui.js +170 -278
  75. package/src/imagestyle/utils.d.ts +101 -0
  76. package/src/imagestyle/utils.js +256 -309
  77. package/src/imagestyle.d.ts +30 -0
  78. package/src/imagestyle.js +13 -261
  79. package/src/imagetextalternative/imagetextalternativecommand.d.ts +34 -0
  80. package/src/imagetextalternative/imagetextalternativecommand.js +31 -47
  81. package/src/imagetextalternative/imagetextalternativeediting.d.ts +27 -0
  82. package/src/imagetextalternative/imagetextalternativeediting.js +18 -25
  83. package/src/imagetextalternative/imagetextalternativeui.d.ts +67 -0
  84. package/src/imagetextalternative/imagetextalternativeui.js +156 -219
  85. package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -0
  86. package/src/imagetextalternative/ui/textalternativeformview.js +103 -192
  87. package/src/imagetextalternative.d.ts +27 -0
  88. package/src/imagetextalternative.js +12 -18
  89. package/src/imagetoolbar.d.ts +33 -0
  90. package/src/imagetoolbar.js +31 -77
  91. package/src/imageupload/imageuploadediting.d.ts +108 -0
  92. package/src/imageupload/imageuploadediting.js +307 -427
  93. package/src/imageupload/imageuploadprogress.d.ts +42 -0
  94. package/src/imageupload/imageuploadprogress.js +180 -261
  95. package/src/imageupload/imageuploadui.d.ts +23 -0
  96. package/src/imageupload/imageuploadui.js +40 -57
  97. package/src/imageupload/uploadimagecommand.d.ts +60 -0
  98. package/src/imageupload/uploadimagecommand.js +73 -87
  99. package/src/imageupload/utils.d.ts +33 -0
  100. package/src/imageupload/utils.js +87 -112
  101. package/src/imageupload.d.ts +29 -0
  102. package/src/imageupload.js +12 -61
  103. package/src/imageutils.d.ts +102 -0
  104. package/src/imageutils.js +232 -329
  105. package/src/index.d.ts +47 -0
  106. package/src/index.js +1 -2
  107. package/src/pictureediting.d.ts +86 -0
  108. package/src/pictureediting.js +101 -120
@@ -0,0 +1,86 @@
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/pictureediting
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ /**
10
+ * This plugin enables the [`<picture>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture) element support in the editor.
11
+ *
12
+ * * It enables the `sources` model attribute on `imageBlock` and `imageInline` model elements
13
+ * (brought by {@link module:image/imageblock~ImageBlock} and {@link module:image/imageinline~ImageInline}, respectively).
14
+ * * It translates the `sources` model element to the view (also: data) structure that may look as follows:
15
+ *
16
+ * ```html
17
+ * <p>Inline image using picture:
18
+ * <picture>
19
+ * <source media="(min-width: 800px)" srcset="image-large.webp" type="image/webp">
20
+ * <source media="(max-width: 800px)" srcset="image-small.webp" type="image/webp">
21
+ * <!-- Other sources as specified in the "sources" model attribute... -->
22
+ * <img src="image.png" alt="An image using picture" />
23
+ * </picture>
24
+ * </p>
25
+ *
26
+ * <p>Block image using picture:</p>
27
+ * <figure class="image">
28
+ * <picture>
29
+ * <source media="(min-width: 800px)" srcset="image-large.webp" type="image/webp">
30
+ * <source media="(max-width: 800px)" srcset="image-small.webp" type="image/webp">
31
+ * <!-- Other sources as specified in the "sources" model attribute... -->
32
+ * <img src="image.png" alt="An image using picture" />
33
+ * </picture>
34
+ * <figcaption>Caption of the image</figcaption>
35
+ * </figure>
36
+ * ```
37
+ *
38
+ * **Note:** The value of the `sources` {@glink framework/guides/architecture/editing-engine#changing-the-model model attribute}
39
+ * in both examples equals:
40
+ *
41
+ * ```css
42
+ * [
43
+ * {
44
+ * media: '(min-width: 800px)',
45
+ * srcset: 'image-large.webp',
46
+ * type: 'image/webp'
47
+ * },
48
+ * {
49
+ * media: '(max-width: 800px)',
50
+ * srcset: 'image-small.webp',
51
+ * type: 'image/webp'
52
+ * }
53
+ * ]
54
+ * ```
55
+ *
56
+ * * It integrates with the {@link module:image/imageupload~ImageUpload} plugin so images uploaded in the editor
57
+ * automatically render using `<picture>` if the {@glink features/images/image-upload/image-upload upload adapter}
58
+ * supports image sources and provides neccessary data.
59
+ *
60
+ * @private
61
+ */
62
+ export default class PictureEditing extends Plugin {
63
+ /**
64
+ * @inheritDoc
65
+ */
66
+ static get requires(): PluginDependencies;
67
+ /**
68
+ * @inheritDoc
69
+ */
70
+ static get pluginName(): 'PictureEditing';
71
+ /**
72
+ * @inheritDoc
73
+ */
74
+ afterInit(): void;
75
+ /**
76
+ * Configures conversion pipelines to support upcasting and downcasting images using the `<picture>` view element
77
+ * and the model `sources` attribute.
78
+ */
79
+ private _setupConversion;
80
+ /**
81
+ * Makes it possible for uploaded images to get the `sources` model attribute and the `<picture>...</picture>`
82
+ * view structure out-of-the-box if relevant data is provided along the
83
+ * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing#event:uploadComplete} event.
84
+ */
85
+ private _setupImageUploadEditingIntegration;
86
+ }
@@ -2,20 +2,13 @@
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/pictureediting
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
-
12
9
  import ImageEditing from './image/imageediting';
13
10
  import ImageUtils from './imageutils';
14
- import {
15
- downcastSourcesAttribute,
16
- upcastPicture
17
- } from './image/converters';
18
-
11
+ import { downcastSourcesAttribute, upcastPicture } from './image/converters';
19
12
  /**
20
13
  * This plugin enables the [`<picture>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture) element support in the editor.
21
14
  *
@@ -23,127 +16,115 @@ import {
23
16
  * (brought by {@link module:image/imageblock~ImageBlock} and {@link module:image/imageinline~ImageInline}, respectively).
24
17
  * * It translates the `sources` model element to the view (also: data) structure that may look as follows:
25
18
  *
26
- * <p>Inline image using picture:
27
- * <picture>
28
- * <source media="(min-width: 800px)" srcset="image-large.webp" type="image/webp">
29
- * <source media="(max-width: 800px)" srcset="image-small.webp" type="image/webp">
30
- * <!-- Other sources as specified in the "sources" model attribute... -->
31
- * <img src="image.png" alt="An image using picture" />
32
- * </picture>
33
- * </p>
19
+ * ```html
20
+ * <p>Inline image using picture:
21
+ * <picture>
22
+ * <source media="(min-width: 800px)" srcset="image-large.webp" type="image/webp">
23
+ * <source media="(max-width: 800px)" srcset="image-small.webp" type="image/webp">
24
+ * <!-- Other sources as specified in the "sources" model attribute... -->
25
+ * <img src="image.png" alt="An image using picture" />
26
+ * </picture>
27
+ * </p>
34
28
  *
35
- * <p>Block image using picture:</p>
36
- * <figure class="image">
37
- * <picture>
38
- * <source media="(min-width: 800px)" srcset="image-large.webp" type="image/webp">
39
- * <source media="(max-width: 800px)" srcset="image-small.webp" type="image/webp">
40
- * <!-- Other sources as specified in the "sources" model attribute... -->
41
- * <img src="image.png" alt="An image using picture" />
42
- * </picture>
43
- * <figcaption>Caption of the image</figcaption>
44
- * </figure>
29
+ * <p>Block image using picture:</p>
30
+ * <figure class="image">
31
+ * <picture>
32
+ * <source media="(min-width: 800px)" srcset="image-large.webp" type="image/webp">
33
+ * <source media="(max-width: 800px)" srcset="image-small.webp" type="image/webp">
34
+ * <!-- Other sources as specified in the "sources" model attribute... -->
35
+ * <img src="image.png" alt="An image using picture" />
36
+ * </picture>
37
+ * <figcaption>Caption of the image</figcaption>
38
+ * </figure>
39
+ * ```
45
40
  *
46
- * **Note:** The value of the `sources` {@glink framework/guides/architecture/editing-engine#changing-the-model model attribute}
47
- * in both examples equals:
41
+ * **Note:** The value of the `sources` {@glink framework/guides/architecture/editing-engine#changing-the-model model attribute}
42
+ * in both examples equals:
48
43
  *
49
- * [
50
- * {
51
- * media: '(min-width: 800px)',
52
- * srcset: 'image-large.webp',
53
- * type: 'image/webp'
54
- * },
55
- * {
56
- * media: '(max-width: 800px)',
57
- * srcset: 'image-small.webp',
58
- * type: 'image/webp'
59
- * }
60
- * ]
44
+ * ```css
45
+ * [
46
+ * {
47
+ * media: '(min-width: 800px)',
48
+ * srcset: 'image-large.webp',
49
+ * type: 'image/webp'
50
+ * },
51
+ * {
52
+ * media: '(max-width: 800px)',
53
+ * srcset: 'image-small.webp',
54
+ * type: 'image/webp'
55
+ * }
56
+ * ]
57
+ * ```
61
58
  *
62
59
  * * It integrates with the {@link module:image/imageupload~ImageUpload} plugin so images uploaded in the editor
63
60
  * automatically render using `<picture>` if the {@glink features/images/image-upload/image-upload upload adapter}
64
61
  * supports image sources and provides neccessary data.
65
62
  *
66
63
  * @private
67
- * @extends module:core/plugin~Plugin
68
64
  */
69
65
  export default class PictureEditing extends Plugin {
70
- /**
71
- * @inheritDoc
72
- */
73
- static get requires() {
74
- return [ ImageEditing, ImageUtils ];
75
- }
76
-
77
- /**
78
- * @inheritDoc
79
- */
80
- static get pluginName() {
81
- return 'PictureEditing';
82
- }
83
-
84
- /**
85
- * @inheritDoc
86
- */
87
- afterInit() {
88
- const editor = this.editor;
89
-
90
- if ( editor.plugins.has( 'ImageBlockEditing' ) ) {
91
- editor.model.schema.extend( 'imageBlock', {
92
- allowAttributes: [ 'sources' ]
93
- } );
94
- }
95
-
96
- if ( editor.plugins.has( 'ImageInlineEditing' ) ) {
97
- editor.model.schema.extend( 'imageInline', {
98
- allowAttributes: [ 'sources' ]
99
- } );
100
- }
101
-
102
- this._setupConversion();
103
- this._setupImageUploadEditingIntegration();
104
- }
105
-
106
- /**
107
- * Configures conversion pipelines to support upcasting and downcasting images using the `<picture>` view element
108
- * and the model `sources` attribute.
109
- *
110
- * @private
111
- */
112
- _setupConversion() {
113
- const editor = this.editor;
114
- const conversion = editor.conversion;
115
- const imageUtils = editor.plugins.get( 'ImageUtils' );
116
-
117
- conversion.for( 'upcast' ).add( upcastPicture( imageUtils ) );
118
- conversion.for( 'downcast' ).add( downcastSourcesAttribute( imageUtils ) );
119
- }
120
-
121
- /**
122
- * Makes it possible for uploaded images to get the `sources` model attribute and the `<picture>...</picture>`
123
- * view structure out-of-the-box if relevant data is provided along the
124
- * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing#event:uploadComplete} event.
125
- *
126
- * @private
127
- */
128
- _setupImageUploadEditingIntegration() {
129
- const editor = this.editor;
130
-
131
- if ( !editor.plugins.has( 'ImageUploadEditing' ) ) {
132
- return;
133
- }
134
-
135
- this.listenTo( editor.plugins.get( 'ImageUploadEditing' ), 'uploadComplete', ( evt, { imageElement, data } ) => {
136
- const sources = data.sources;
137
-
138
- if ( !sources ) {
139
- return;
140
- }
141
-
142
- editor.model.change( writer => {
143
- writer.setAttributes( {
144
- sources
145
- }, imageElement );
146
- } );
147
- } );
148
- }
66
+ /**
67
+ * @inheritDoc
68
+ */
69
+ static get requires() {
70
+ return [ImageEditing, ImageUtils];
71
+ }
72
+ /**
73
+ * @inheritDoc
74
+ */
75
+ static get pluginName() {
76
+ return 'PictureEditing';
77
+ }
78
+ /**
79
+ * @inheritDoc
80
+ */
81
+ afterInit() {
82
+ const editor = this.editor;
83
+ if (editor.plugins.has('ImageBlockEditing')) {
84
+ editor.model.schema.extend('imageBlock', {
85
+ allowAttributes: ['sources']
86
+ });
87
+ }
88
+ if (editor.plugins.has('ImageInlineEditing')) {
89
+ editor.model.schema.extend('imageInline', {
90
+ allowAttributes: ['sources']
91
+ });
92
+ }
93
+ this._setupConversion();
94
+ this._setupImageUploadEditingIntegration();
95
+ }
96
+ /**
97
+ * Configures conversion pipelines to support upcasting and downcasting images using the `<picture>` view element
98
+ * and the model `sources` attribute.
99
+ */
100
+ _setupConversion() {
101
+ const editor = this.editor;
102
+ const conversion = editor.conversion;
103
+ const imageUtils = editor.plugins.get('ImageUtils');
104
+ conversion.for('upcast').add(upcastPicture(imageUtils));
105
+ conversion.for('downcast').add(downcastSourcesAttribute(imageUtils));
106
+ }
107
+ /**
108
+ * Makes it possible for uploaded images to get the `sources` model attribute and the `<picture>...</picture>`
109
+ * view structure out-of-the-box if relevant data is provided along the
110
+ * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing#event:uploadComplete} event.
111
+ */
112
+ _setupImageUploadEditingIntegration() {
113
+ const editor = this.editor;
114
+ if (!editor.plugins.has('ImageUploadEditing')) {
115
+ return;
116
+ }
117
+ const imageUploadEditing = editor.plugins.get('ImageUploadEditing');
118
+ this.listenTo(imageUploadEditing, 'uploadComplete', (evt, { imageElement, data }) => {
119
+ const sources = data.sources;
120
+ if (!sources) {
121
+ return;
122
+ }
123
+ editor.model.change(writer => {
124
+ writer.setAttributes({
125
+ sources
126
+ }, imageElement);
127
+ });
128
+ });
129
+ }
149
130
  }