@ckeditor/ckeditor5-image 47.6.1 → 48.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 (289) hide show
  1. package/LICENSE.md +1 -1
  2. package/ckeditor5-metadata.json +25 -25
  3. package/{src → dist}/autoimage.d.ts +4 -4
  4. package/{src → dist}/image/converters.d.ts +1 -1
  5. package/{src → dist}/image/imageblockediting.d.ts +2 -2
  6. package/{src → dist}/image/imageediting.d.ts +1 -1
  7. package/{src → dist}/image/imageinlineediting.d.ts +2 -2
  8. package/{src → dist}/image/imageloadobserver.d.ts +1 -1
  9. package/{src → dist}/image/imageplaceholder.d.ts +1 -1
  10. package/{src → dist}/image/imagetypecommand.d.ts +2 -2
  11. package/{src → dist}/image/insertimagecommand.d.ts +2 -2
  12. package/{src → dist}/image/replaceimagesourcecommand.d.ts +2 -2
  13. package/{src → dist}/image/ui/utils.d.ts +2 -2
  14. package/{src → dist}/image/utils.d.ts +2 -2
  15. package/{src → dist}/image.d.ts +1 -1
  16. package/{src → dist}/imageblock.d.ts +2 -2
  17. package/{src → dist}/imagecaption/imagecaptionediting.d.ts +2 -2
  18. package/{src → dist}/imagecaption/imagecaptionui.d.ts +1 -1
  19. package/{src → dist}/imagecaption/imagecaptionutils.d.ts +2 -2
  20. package/{src → dist}/imagecaption/toggleimagecaptioncommand.d.ts +1 -1
  21. package/{src → dist}/imagecaption.d.ts +1 -1
  22. package/{src → dist}/imageconfig.d.ts +25 -16
  23. package/{src → dist}/imageinline.d.ts +2 -2
  24. package/{src → dist}/imageinsert/imageinsertui.d.ts +3 -3
  25. package/{src → dist}/imageinsert/imageinsertviaurlui.d.ts +2 -2
  26. package/{src → dist}/imageinsert/ui/imageinsertformview.d.ts +2 -2
  27. package/{src → dist}/imageinsert/ui/imageinserturlview.d.ts +2 -2
  28. package/{src → dist}/imageinsert.d.ts +1 -1
  29. package/{src → dist}/imageinsertviaurl.d.ts +1 -1
  30. package/{src → dist}/imageresize/imagecustomresizeui.d.ts +2 -2
  31. package/{src → dist}/imageresize/imageresizebuttons.d.ts +1 -1
  32. package/{src → dist}/imageresize/imageresizeediting.d.ts +1 -1
  33. package/{src → dist}/imageresize/imageresizehandles.d.ts +2 -2
  34. package/{src → dist}/imageresize/resizeimagecommand.d.ts +1 -1
  35. package/{src → dist}/imageresize/ui/imagecustomresizeformview.d.ts +2 -4
  36. package/{src → dist}/imageresize/utils/getselectedimageeditornodes.d.ts +2 -2
  37. package/{src → dist}/imageresize/utils/getselectedimagepossibleresizerange.d.ts +1 -1
  38. package/{src → dist}/imageresize/utils/getselectedimagewidthinunits.d.ts +1 -1
  39. package/{src → dist}/imageresize.d.ts +1 -1
  40. package/{src → dist}/imagesizeattributes.d.ts +1 -1
  41. package/{src → dist}/imagestyle/converters.d.ts +2 -2
  42. package/{src → dist}/imagestyle/imagestylecommand.d.ts +2 -2
  43. package/{src → dist}/imagestyle/imagestyleediting.d.ts +1 -1
  44. package/{src → dist}/imagestyle/imagestyleui.d.ts +1 -1
  45. package/{src → dist}/imagestyle/utils.d.ts +1 -1
  46. package/{src → dist}/imagestyle.d.ts +1 -1
  47. package/{src → dist}/imagetextalternative/imagetextalternativecommand.d.ts +1 -1
  48. package/{src → dist}/imagetextalternative/imagetextalternativeediting.d.ts +1 -1
  49. package/{src → dist}/imagetextalternative/imagetextalternativeui.d.ts +2 -2
  50. package/{src → dist}/imagetextalternative/ui/textalternativeformview.d.ts +2 -4
  51. package/{src → dist}/imagetextalternative.d.ts +1 -1
  52. package/{src → dist}/imagetoolbar.d.ts +2 -2
  53. package/{src → dist}/imageupload/imageuploadediting.d.ts +5 -5
  54. package/{src → dist}/imageupload/imageuploadprogress.d.ts +1 -1
  55. package/{src → dist}/imageupload/imageuploadui.d.ts +1 -1
  56. package/{src → dist}/imageupload/uploadimagecommand.d.ts +2 -2
  57. package/{src → dist}/imageupload/utils.d.ts +1 -1
  58. package/{src → dist}/imageupload.d.ts +1 -1
  59. package/{src → dist}/imageutils.d.ts +2 -2
  60. package/dist/index-content.css +97 -100
  61. package/dist/index-editor.css +313 -190
  62. package/dist/index.css +388 -458
  63. package/dist/index.css.map +1 -1
  64. package/dist/index.js +1 -2
  65. package/dist/index.js.map +1 -1
  66. package/{src → dist}/pictureediting.d.ts +1 -1
  67. package/package.json +29 -53
  68. package/build/image.js +0 -5
  69. package/build/translations/af.js +0 -1
  70. package/build/translations/ar.js +0 -1
  71. package/build/translations/ast.js +0 -1
  72. package/build/translations/az.js +0 -1
  73. package/build/translations/be.js +0 -1
  74. package/build/translations/bg.js +0 -1
  75. package/build/translations/bn.js +0 -1
  76. package/build/translations/bs.js +0 -1
  77. package/build/translations/ca.js +0 -1
  78. package/build/translations/cs.js +0 -1
  79. package/build/translations/da.js +0 -1
  80. package/build/translations/de-ch.js +0 -1
  81. package/build/translations/de.js +0 -1
  82. package/build/translations/el.js +0 -1
  83. package/build/translations/en-au.js +0 -1
  84. package/build/translations/en-gb.js +0 -1
  85. package/build/translations/eo.js +0 -1
  86. package/build/translations/es-co.js +0 -1
  87. package/build/translations/es.js +0 -1
  88. package/build/translations/et.js +0 -1
  89. package/build/translations/eu.js +0 -1
  90. package/build/translations/fa.js +0 -1
  91. package/build/translations/fi.js +0 -1
  92. package/build/translations/fr.js +0 -1
  93. package/build/translations/gl.js +0 -1
  94. package/build/translations/gu.js +0 -1
  95. package/build/translations/he.js +0 -1
  96. package/build/translations/hi.js +0 -1
  97. package/build/translations/hr.js +0 -1
  98. package/build/translations/hu.js +0 -1
  99. package/build/translations/hy.js +0 -1
  100. package/build/translations/id.js +0 -1
  101. package/build/translations/it.js +0 -1
  102. package/build/translations/ja.js +0 -1
  103. package/build/translations/jv.js +0 -1
  104. package/build/translations/kk.js +0 -1
  105. package/build/translations/km.js +0 -1
  106. package/build/translations/kn.js +0 -1
  107. package/build/translations/ko.js +0 -1
  108. package/build/translations/ku.js +0 -1
  109. package/build/translations/lt.js +0 -1
  110. package/build/translations/lv.js +0 -1
  111. package/build/translations/ms.js +0 -1
  112. package/build/translations/nb.js +0 -1
  113. package/build/translations/ne.js +0 -1
  114. package/build/translations/nl.js +0 -1
  115. package/build/translations/no.js +0 -1
  116. package/build/translations/oc.js +0 -1
  117. package/build/translations/pl.js +0 -1
  118. package/build/translations/pt-br.js +0 -1
  119. package/build/translations/pt.js +0 -1
  120. package/build/translations/ro.js +0 -1
  121. package/build/translations/ru.js +0 -1
  122. package/build/translations/si.js +0 -1
  123. package/build/translations/sk.js +0 -1
  124. package/build/translations/sl.js +0 -1
  125. package/build/translations/sq.js +0 -1
  126. package/build/translations/sr-latn.js +0 -1
  127. package/build/translations/sr.js +0 -1
  128. package/build/translations/sv.js +0 -1
  129. package/build/translations/th.js +0 -1
  130. package/build/translations/ti.js +0 -1
  131. package/build/translations/tk.js +0 -1
  132. package/build/translations/tr.js +0 -1
  133. package/build/translations/tt.js +0 -1
  134. package/build/translations/ug.js +0 -1
  135. package/build/translations/uk.js +0 -1
  136. package/build/translations/ur.js +0 -1
  137. package/build/translations/uz.js +0 -1
  138. package/build/translations/vi.js +0 -1
  139. package/build/translations/zh-cn.js +0 -1
  140. package/build/translations/zh.js +0 -1
  141. package/lang/contexts.json +0 -48
  142. package/lang/translations/af.po +0 -196
  143. package/lang/translations/ar.po +0 -196
  144. package/lang/translations/ast.po +0 -196
  145. package/lang/translations/az.po +0 -196
  146. package/lang/translations/be.po +0 -196
  147. package/lang/translations/bg.po +0 -196
  148. package/lang/translations/bn.po +0 -196
  149. package/lang/translations/bs.po +0 -196
  150. package/lang/translations/ca.po +0 -196
  151. package/lang/translations/cs.po +0 -196
  152. package/lang/translations/da.po +0 -196
  153. package/lang/translations/de-ch.po +0 -196
  154. package/lang/translations/de.po +0 -196
  155. package/lang/translations/el.po +0 -196
  156. package/lang/translations/en-au.po +0 -196
  157. package/lang/translations/en-gb.po +0 -196
  158. package/lang/translations/en.po +0 -196
  159. package/lang/translations/eo.po +0 -196
  160. package/lang/translations/es-co.po +0 -196
  161. package/lang/translations/es.po +0 -196
  162. package/lang/translations/et.po +0 -196
  163. package/lang/translations/eu.po +0 -196
  164. package/lang/translations/fa.po +0 -196
  165. package/lang/translations/fi.po +0 -196
  166. package/lang/translations/fr.po +0 -196
  167. package/lang/translations/gl.po +0 -196
  168. package/lang/translations/gu.po +0 -196
  169. package/lang/translations/he.po +0 -196
  170. package/lang/translations/hi.po +0 -196
  171. package/lang/translations/hr.po +0 -196
  172. package/lang/translations/hu.po +0 -196
  173. package/lang/translations/hy.po +0 -196
  174. package/lang/translations/id.po +0 -196
  175. package/lang/translations/it.po +0 -196
  176. package/lang/translations/ja.po +0 -196
  177. package/lang/translations/jv.po +0 -196
  178. package/lang/translations/kk.po +0 -196
  179. package/lang/translations/km.po +0 -196
  180. package/lang/translations/kn.po +0 -196
  181. package/lang/translations/ko.po +0 -196
  182. package/lang/translations/ku.po +0 -196
  183. package/lang/translations/lt.po +0 -196
  184. package/lang/translations/lv.po +0 -196
  185. package/lang/translations/ms.po +0 -196
  186. package/lang/translations/nb.po +0 -196
  187. package/lang/translations/ne.po +0 -196
  188. package/lang/translations/nl.po +0 -196
  189. package/lang/translations/no.po +0 -196
  190. package/lang/translations/oc.po +0 -196
  191. package/lang/translations/pl.po +0 -196
  192. package/lang/translations/pt-br.po +0 -196
  193. package/lang/translations/pt.po +0 -196
  194. package/lang/translations/ro.po +0 -196
  195. package/lang/translations/ru.po +0 -196
  196. package/lang/translations/si.po +0 -196
  197. package/lang/translations/sk.po +0 -196
  198. package/lang/translations/sl.po +0 -196
  199. package/lang/translations/sq.po +0 -196
  200. package/lang/translations/sr-latn.po +0 -196
  201. package/lang/translations/sr.po +0 -196
  202. package/lang/translations/sv.po +0 -196
  203. package/lang/translations/th.po +0 -196
  204. package/lang/translations/ti.po +0 -196
  205. package/lang/translations/tk.po +0 -196
  206. package/lang/translations/tr.po +0 -196
  207. package/lang/translations/tt.po +0 -196
  208. package/lang/translations/ug.po +0 -196
  209. package/lang/translations/uk.po +0 -196
  210. package/lang/translations/ur.po +0 -196
  211. package/lang/translations/uz.po +0 -196
  212. package/lang/translations/vi.po +0 -196
  213. package/lang/translations/zh-cn.po +0 -196
  214. package/lang/translations/zh.po +0 -196
  215. package/src/augmentation.js +0 -5
  216. package/src/autoimage.js +0 -148
  217. package/src/image/converters.js +0 -236
  218. package/src/image/imageblockediting.js +0 -159
  219. package/src/image/imageediting.js +0 -69
  220. package/src/image/imageinlineediting.js +0 -178
  221. package/src/image/imageloadobserver.js +0 -52
  222. package/src/image/imageplaceholder.js +0 -119
  223. package/src/image/imagetypecommand.js +0 -84
  224. package/src/image/insertimagecommand.js +0 -125
  225. package/src/image/replaceimagesourcecommand.js +0 -75
  226. package/src/image/ui/utils.js +0 -46
  227. package/src/image/utils.js +0 -125
  228. package/src/image.js +0 -44
  229. package/src/imageblock.js +0 -44
  230. package/src/imagecaption/imagecaptionediting.js +0 -238
  231. package/src/imagecaption/imagecaptionui.js +0 -68
  232. package/src/imagecaption/imagecaptionutils.js +0 -68
  233. package/src/imagecaption/toggleimagecaptioncommand.js +0 -138
  234. package/src/imagecaption.js +0 -36
  235. package/src/imageconfig.js +0 -5
  236. package/src/imageinline.js +0 -44
  237. package/src/imageinsert/imageinsertui.js +0 -216
  238. package/src/imageinsert/imageinsertviaurlui.js +0 -175
  239. package/src/imageinsert/ui/imageinsertformview.js +0 -117
  240. package/src/imageinsert/ui/imageinserturlview.js +0 -102
  241. package/src/imageinsert.js +0 -43
  242. package/src/imageinsertviaurl.js +0 -41
  243. package/src/imageresize/imagecustomresizeui.js +0 -177
  244. package/src/imageresize/imageresizebuttons.js +0 -303
  245. package/src/imageresize/imageresizeediting.js +0 -206
  246. package/src/imageresize/imageresizehandles.js +0 -118
  247. package/src/imageresize/resizeimagecommand.js +0 -63
  248. package/src/imageresize/ui/imagecustomresizeformview.js +0 -264
  249. package/src/imageresize/utils/getselectedimageeditornodes.js +0 -25
  250. package/src/imageresize/utils/getselectedimagepossibleresizerange.js +0 -33
  251. package/src/imageresize/utils/getselectedimagewidthinunits.js +0 -42
  252. package/src/imageresize/utils/tryparsedimensionwithunit.js +0 -58
  253. package/src/imageresize.js +0 -38
  254. package/src/imagesizeattributes.js +0 -163
  255. package/src/imagestyle/converters.js +0 -118
  256. package/src/imagestyle/imagestylecommand.js +0 -117
  257. package/src/imagestyle/imagestyleediting.js +0 -127
  258. package/src/imagestyle/imagestyleui.js +0 -198
  259. package/src/imagestyle/utils.js +0 -333
  260. package/src/imagestyle.js +0 -42
  261. package/src/imagetextalternative/imagetextalternativecommand.js +0 -44
  262. package/src/imagetextalternative/imagetextalternativeediting.js +0 -41
  263. package/src/imagetextalternative/imagetextalternativeui.js +0 -183
  264. package/src/imagetextalternative/ui/textalternativeformview.js +0 -193
  265. package/src/imagetextalternative.js +0 -39
  266. package/src/imagetoolbar.js +0 -63
  267. package/src/imageupload/imageuploadediting.js +0 -482
  268. package/src/imageupload/imageuploadprogress.js +0 -222
  269. package/src/imageupload/imageuploadui.js +0 -135
  270. package/src/imageupload/uploadimagecommand.js +0 -110
  271. package/src/imageupload/utils.js +0 -114
  272. package/src/imageupload.js +0 -42
  273. package/src/imageutils.js +0 -309
  274. package/src/index.js +0 -67
  275. package/src/pictureediting.js +0 -136
  276. package/theme/image.css +0 -143
  277. package/theme/imagecaption.css +0 -53
  278. package/theme/imagecustomresizeform.css +0 -4
  279. package/theme/imageinsert.css +0 -14
  280. package/theme/imageplaceholder.css +0 -10
  281. package/theme/imageresize.css +0 -53
  282. package/theme/imagestyle.css +0 -120
  283. package/theme/imageuploadicon.css +0 -23
  284. package/theme/imageuploadloader.css +0 -18
  285. package/theme/imageuploadprogress.css +0 -19
  286. package/theme/textalternativeform.css +0 -4
  287. /package/{src → dist}/augmentation.d.ts +0 -0
  288. /package/{src → dist}/imageresize/utils/tryparsedimensionwithunit.d.ts +0 -0
  289. /package/{src → dist}/index.d.ts +0 -0
package/src/imageutils.js DELETED
@@ -1,309 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- import { Plugin } from 'ckeditor5/src/core.js';
6
- import { findOptimalInsertionRange, isWidget, toWidget } from 'ckeditor5/src/widget.js';
7
- import { determineImageTypeForInsertionAtSelection } from './image/utils.js';
8
- import { DomEmitterMixin, global } from 'ckeditor5/src/utils.js';
9
- const IMAGE_WIDGETS_CLASSES_MATCH_REGEXP = /^(image|image-inline)$/;
10
- /**
11
- * A set of helpers related to images.
12
- */
13
- export class ImageUtils extends Plugin {
14
- /**
15
- * DOM Emitter.
16
- */
17
- _domEmitter = new (DomEmitterMixin())();
18
- /**
19
- * @inheritDoc
20
- */
21
- static get pluginName() {
22
- return 'ImageUtils';
23
- }
24
- /**
25
- * @inheritDoc
26
- */
27
- static get isOfficialPlugin() {
28
- return true;
29
- }
30
- /**
31
- * Checks if the provided model element is an `image` or `imageInline`.
32
- */
33
- isImage(modelElement) {
34
- return this.isInlineImage(modelElement) || this.isBlockImage(modelElement);
35
- }
36
- /**
37
- * Checks if the provided view element represents an inline image.
38
- *
39
- * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
40
- */
41
- isInlineImageView(element) {
42
- return !!element && element.is('element', 'img');
43
- }
44
- /**
45
- * Checks if the provided view element represents a block image.
46
- *
47
- * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
48
- */
49
- isBlockImageView(element) {
50
- return !!element && element.is('element', 'figure') && element.hasClass('image');
51
- }
52
- /**
53
- * Handles inserting single file. This method unifies image insertion using {@link module:widget/utils~findOptimalInsertionRange}
54
- * method.
55
- *
56
- * ```ts
57
- * const imageUtils = editor.plugins.get( 'ImageUtils' );
58
- *
59
- * imageUtils.insertImage( { src: 'path/to/image.jpg' } );
60
- * ```
61
- *
62
- * @param attributes Attributes of the inserted image.
63
- * This method filters out the attributes which are disallowed by the {@link module:engine/model/schema~ModelSchema}.
64
- * @param selectable Place to insert the image. If not specified,
65
- * the {@link module:widget/utils~findOptimalInsertionRange} logic will be applied for the block images
66
- * and `model.document.selection` for the inline images.
67
- *
68
- * **Note**: If `selectable` is passed, this helper will not be able to set selection attributes (such as `linkHref`)
69
- * and apply them to the new image. In this case, make sure all selection attributes are passed in `attributes`.
70
- *
71
- * @param imageType Image type of inserted image. If not specified,
72
- * it will be determined automatically depending of editor config or place of the insertion.
73
- * @param options.setImageSizes Specifies whether the image `width` and `height` attributes should be set automatically.
74
- * The default is `true`.
75
- * @return The inserted model image element.
76
- */
77
- insertImage(attributes = {}, selectable = null, imageType = null, options = {}) {
78
- const editor = this.editor;
79
- const model = editor.model;
80
- const selection = model.document.selection;
81
- const determinedImageType = determineImageTypeForInsertion(editor, selectable || selection, imageType);
82
- // Mix declarative attributes with selection attributes because the new image should "inherit"
83
- // the latter for best UX. For instance, inline images inserted into existing links
84
- // should not split them. To do that, they need to have "linkHref" inherited from the selection.
85
- attributes = {
86
- ...Object.fromEntries(selection.getAttributes()),
87
- ...attributes
88
- };
89
- for (const attributeName in attributes) {
90
- if (!model.schema.checkAttribute(determinedImageType, attributeName)) {
91
- delete attributes[attributeName];
92
- }
93
- }
94
- return model.change(writer => {
95
- const { setImageSizes = true } = options;
96
- const imageElement = writer.createElement(determinedImageType, attributes);
97
- model.insertObject(imageElement, selectable, null, {
98
- setSelection: 'on',
99
- // If we want to insert a block image (for whatever reason) then we don't want to split text blocks.
100
- // This applies only when we don't have the selectable specified (i.e., we insert multiple block images at once).
101
- findOptimalPosition: !selectable && determinedImageType != 'imageInline' ? 'auto' : undefined
102
- });
103
- // Inserting an image might've failed due to schema regulations.
104
- if (imageElement.parent) {
105
- if (setImageSizes) {
106
- this.setImageNaturalSizeAttributes(imageElement);
107
- }
108
- return imageElement;
109
- }
110
- return null;
111
- });
112
- }
113
- /**
114
- * Reads original image sizes and sets them as `width` and `height`.
115
- *
116
- * The `src` attribute may not be available if the user is using an upload adapter. In such a case,
117
- * this method is called again after the upload process is complete and the `src` attribute is available.
118
- */
119
- setImageNaturalSizeAttributes(imageElement) {
120
- const src = imageElement.getAttribute('src');
121
- if (!src) {
122
- return;
123
- }
124
- if (imageElement.getAttribute('width') || imageElement.getAttribute('height')) {
125
- return;
126
- }
127
- this.editor.model.change(writer => {
128
- const img = new global.window.Image();
129
- this._domEmitter.listenTo(img, 'load', () => {
130
- if (!imageElement.getAttribute('width') && !imageElement.getAttribute('height')) {
131
- // We use writer.batch to be able to undo (in a single step) width and height setting
132
- // along with any change that triggered this action (e.g. image resize or image style change).
133
- this.editor.model.enqueueChange(writer.batch, writer => {
134
- writer.setAttribute('width', img.naturalWidth, imageElement);
135
- writer.setAttribute('height', img.naturalHeight, imageElement);
136
- });
137
- }
138
- this._domEmitter.stopListening(img, 'load');
139
- });
140
- img.src = src;
141
- });
142
- }
143
- /**
144
- * Returns an image widget editing view element if one is selected or is among the selection's ancestors.
145
- */
146
- getClosestSelectedImageWidget(selection) {
147
- const selectionPosition = selection.getFirstPosition();
148
- if (!selectionPosition) {
149
- return null;
150
- }
151
- const viewElement = selection.getSelectedElement();
152
- if (viewElement && this.isImageWidget(viewElement)) {
153
- return viewElement;
154
- }
155
- let parent = selectionPosition.parent;
156
- while (parent) {
157
- if (parent.is('element') && this.isImageWidget(parent)) {
158
- return parent;
159
- }
160
- parent = parent.parent;
161
- }
162
- return null;
163
- }
164
- /**
165
- * Returns a image model element if one is selected or is among the selection's ancestors.
166
- */
167
- getClosestSelectedImageElement(selection) {
168
- const selectedElement = selection.getSelectedElement();
169
- return this.isImage(selectedElement) ? selectedElement : selection.getFirstPosition().findAncestor('imageBlock');
170
- }
171
- /**
172
- * Returns an image widget editing view based on the passed image view.
173
- */
174
- getImageWidgetFromImageView(imageView) {
175
- return imageView.findAncestor({ classes: IMAGE_WIDGETS_CLASSES_MATCH_REGEXP });
176
- }
177
- /**
178
- * Checks if image can be inserted at current model selection.
179
- *
180
- * @internal
181
- */
182
- isImageAllowed() {
183
- const model = this.editor.model;
184
- const selection = model.document.selection;
185
- return isImageAllowedInParent(this.editor, selection) && isNotInsideImage(selection);
186
- }
187
- /**
188
- * Converts a given {@link module:engine/view/element~ViewElement} to an image widget:
189
- * * Adds a {@link module:engine/view/element~ViewElement#_setCustomProperty custom property} allowing to recognize the image widget
190
- * element.
191
- * * Calls the {@link module:widget/utils~toWidget} function with the proper element's label creator.
192
- *
193
- * @param writer An instance of the view writer.
194
- * @param label The element's label. It will be concatenated with the image `alt` attribute if one is present.
195
- */
196
- toImageWidget(viewElement, writer, label) {
197
- writer.setCustomProperty('image', true, viewElement);
198
- const labelCreator = () => {
199
- const imgElement = this.findViewImgElement(viewElement);
200
- const altText = imgElement.getAttribute('alt');
201
- return altText ? `${altText} ${label}` : label;
202
- };
203
- return toWidget(viewElement, writer, { label: labelCreator });
204
- }
205
- /**
206
- * Checks if a given view element is an image widget.
207
- */
208
- isImageWidget(viewElement) {
209
- return !!viewElement.getCustomProperty('image') && isWidget(viewElement);
210
- }
211
- /**
212
- * Checks if the provided model element is an `image`.
213
- */
214
- isBlockImage(modelElement) {
215
- return !!modelElement && modelElement.is('element', 'imageBlock');
216
- }
217
- /**
218
- * Checks if the provided model element is an `imageInline`.
219
- */
220
- isInlineImage(modelElement) {
221
- return !!modelElement && modelElement.is('element', 'imageInline');
222
- }
223
- /**
224
- * Get the view `<img>` from another view element, e.g. a widget (`<figure class="image">`), a link (`<a>`).
225
- *
226
- * The `<img>` can be located deep in other elements, so this helper performs a deep tree search.
227
- */
228
- findViewImgElement(figureView) {
229
- if (this.isInlineImageView(figureView)) {
230
- return figureView;
231
- }
232
- const editingView = this.editor.editing.view;
233
- for (const { item } of editingView.createRangeIn(figureView)) {
234
- if (this.isInlineImageView(item)) {
235
- return item;
236
- }
237
- }
238
- }
239
- /**
240
- * @inheritDoc
241
- */
242
- destroy() {
243
- this._domEmitter.stopListening();
244
- return super.destroy();
245
- }
246
- }
247
- /**
248
- * Checks if image is allowed by schema in optimal insertion parent.
249
- */
250
- function isImageAllowedInParent(editor, selection) {
251
- const imageType = determineImageTypeForInsertion(editor, selection, null);
252
- if (imageType == 'imageBlock') {
253
- const parent = getInsertImageParent(selection, editor.model);
254
- if (editor.model.schema.checkChild(parent, 'imageBlock')) {
255
- return true;
256
- }
257
- }
258
- else if (editor.model.schema.checkChild(selection.focus, 'imageInline')) {
259
- return true;
260
- }
261
- return false;
262
- }
263
- /**
264
- * Checks if selection is not placed inside an image (e.g. its caption).
265
- */
266
- function isNotInsideImage(selection) {
267
- return [...selection.focus.getAncestors()].every(ancestor => !ancestor.is('element', 'imageBlock'));
268
- }
269
- /**
270
- * Returns a node that will be used to insert image with `model.insertContent`.
271
- */
272
- function getInsertImageParent(selection, model) {
273
- const insertionRange = findOptimalInsertionRange(selection, model);
274
- const parent = insertionRange.start.parent;
275
- if (parent.isEmpty && !parent.is('element', '$root')) {
276
- return parent.parent;
277
- }
278
- return parent;
279
- }
280
- /**
281
- * Determine image element type name depending on editor config or place of insertion.
282
- *
283
- * @param imageType Image element type name. Used to force return of provided element name,
284
- * but only if there is proper plugin enabled.
285
- */
286
- function determineImageTypeForInsertion(editor, selectable, imageType) {
287
- const schema = editor.model.schema;
288
- const configImageInsertType = editor.config.get('image.insert.type');
289
- if (!editor.plugins.has('ImageBlockEditing')) {
290
- return 'imageInline';
291
- }
292
- if (!editor.plugins.has('ImageInlineEditing')) {
293
- return 'imageBlock';
294
- }
295
- if (imageType) {
296
- return imageType;
297
- }
298
- if (configImageInsertType === 'inline') {
299
- return 'imageInline';
300
- }
301
- if (configImageInsertType !== 'auto') {
302
- return 'imageBlock';
303
- }
304
- // Try to replace the selected widget (e.g. another image).
305
- if (selectable.is('selection')) {
306
- return determineImageTypeForInsertionAtSelection(schema, selectable);
307
- }
308
- return schema.checkChild(selectable, 'imageInline') ? 'imageInline' : 'imageBlock';
309
- }
package/src/index.js DELETED
@@ -1,67 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module image
7
- */
8
- export { AutoImage } from './autoimage.js';
9
- export { Image } from './image.js';
10
- export { ImageEditing } from './image/imageediting.js';
11
- export { ImageCaptionUtils } from './imagecaption/imagecaptionutils.js';
12
- export { ImageCaption } from './imagecaption.js';
13
- export { ImageCaptionEditing } from './imagecaption/imagecaptionediting.js';
14
- export { ImageInsert } from './imageinsert.js';
15
- export { ImageInsertUI } from './imageinsert/imageinsertui.js';
16
- export { ImageInsertViaUrlUI } from './imageinsert/imageinsertviaurlui.js';
17
- export { ImageResize } from './imageresize.js';
18
- export { ImageResizeButtons } from './imageresize/imageresizebuttons.js';
19
- export { ImageResizeEditing } from './imageresize/imageresizeediting.js';
20
- export { ImageResizeHandles } from './imageresize/imageresizehandles.js';
21
- export { ImageCustomResizeUI } from './imageresize/imagecustomresizeui.js';
22
- export { ImageSizeAttributes } from './imagesizeattributes.js';
23
- export { ImageStyle } from './imagestyle.js';
24
- export { ImageStyleEditing } from './imagestyle/imagestyleediting.js';
25
- export { ImageStyleUI } from './imagestyle/imagestyleui.js';
26
- export { ImageTextAlternative } from './imagetextalternative.js';
27
- export { ImageTextAlternativeEditing } from './imagetextalternative/imagetextalternativeediting.js';
28
- export { ImageTextAlternativeUI } from './imagetextalternative/imagetextalternativeui.js';
29
- export { ImageToolbar } from './imagetoolbar.js';
30
- export { ImageUpload } from './imageupload.js';
31
- export { ImageUploadEditing, isHtmlInDataTransfer } from './imageupload/imageuploadediting.js';
32
- export { ImageUploadProgress } from './imageupload/imageuploadprogress.js';
33
- export { ImageUploadUI } from './imageupload/imageuploadui.js';
34
- export { PictureEditing } from './pictureediting.js';
35
- export { ImageBlock } from './imageblock.js';
36
- export { ImageInline } from './imageinline.js';
37
- export { ImageInsertViaUrl } from './imageinsertviaurl.js';
38
- export { ImageUtils } from './imageutils.js';
39
- export { ImageBlockEditing } from './image/imageblockediting.js';
40
- export { ImageCaptionUI } from './imagecaption/imagecaptionui.js';
41
- export { ImageInlineEditing } from './image/imageinlineediting.js';
42
- export { ImagePlaceholder } from './image/imageplaceholder.js';
43
- export { createImageTypeRegExp } from './imageupload/utils.js';
44
- export { ImageLoadObserver } from './image/imageloadobserver.js';
45
- export { ImageTypeCommand } from './image/imagetypecommand.js';
46
- export { InsertImageCommand } from './image/insertimagecommand.js';
47
- export { ReplaceImageSourceCommand } from './image/replaceimagesourcecommand.js';
48
- export { ToggleImageCaptionCommand } from './imagecaption/toggleimagecaptioncommand.js';
49
- export { ResizeImageCommand } from './imageresize/resizeimagecommand.js';
50
- export { ImageStyleCommand } from './imagestyle/imagestylecommand.js';
51
- export { ImageTextAlternativeCommand } from './imagetextalternative/imagetextalternativecommand.js';
52
- export { UploadImageCommand } from './imageupload/uploadimagecommand.js';
53
- export { upcastImageFigure as _upcastImageFigure, upcastPicture as _upcastImagePicture, downcastSrcsetAttribute as _downcastImageSrcsetAttribute, downcastSourcesAttribute as _downcastImageSourcesAttribute, downcastImageAttribute as _downcastImageAttribute } from './image/converters.js';
54
- export { repositionContextualBalloon as _repositionImageContextualBalloon, getBalloonPositionData as _getImageBalloonPositionData } from './image/ui/utils.js';
55
- export { createInlineImageViewElement as _createInlineImageViewElement, createBlockImageViewElement as _createBlockImageViewElement, getImgViewElementMatcher as _getImageViewElementMatcher, determineImageTypeForInsertionAtSelection as _determineImageTypeForInsertionAtSelection, getSizeValueIfInPx as _getImageSizeValueIfInPx, widthAndHeightStylesAreBothSet as _checkIfImageWidthAndHeightStylesAreBothSet } from './image/utils.js';
56
- export { ImageInsertFormView as _ImageInsertFormView } from './imageinsert/ui/imageinsertformview.js';
57
- export { ImageInsertUrlView as _ImageInsertUrlView } from './imageinsert/ui/imageinserturlview.js';
58
- export { ImageCustomResizeFormView as _ImageCustomResizeFormView } from './imageresize/ui/imagecustomresizeformview.js';
59
- export { getSelectedImageEditorNodes as _getSelectedImageEditorNodes } from './imageresize/utils/getselectedimageeditornodes.js';
60
- export { getSelectedImagePossibleResizeRange as _getSelectedImagePossibleResizeRange } from './imageresize/utils/getselectedimagepossibleresizerange.js';
61
- export { getSelectedImageWidthInUnits as _getSelectedImageWidthInUnits } from './imageresize/utils/getselectedimagewidthinunits.js';
62
- export { tryParseDimensionWithUnit as _tryParseImageDimensionWithUnit, tryCastDimensionsToUnit as _tryCastImageDimensionsToUnit } from './imageresize/utils/tryparsedimensionwithunit.js';
63
- export { modelToViewStyleAttribute as _modelToViewImageStyleAttribute, viewToModelStyleAttribute as _viewToModelImageStyleAttribute } from './imagestyle/converters.js';
64
- export { utils as _ImageStyleUtils, DEFAULT_OPTIONS as _IMAGE_DEFAULT_OPTIONS, DEFAULT_ICONS as _IMAGE_DEFAULT_ICONS, DEFAULT_DROPDOWN_DEFINITIONS as _IMAGE_DEFAULT_DROPDOWN_DEFINITIONS } from './imagestyle/utils.js';
65
- export { TextAlternativeFormView as _ImageTextAlternativeFormView } from './imagetextalternative/ui/textalternativeformview.js';
66
- export { fetchLocalImage as _fetchLocalImage, isLocalImage as _isLocalImage } from './imageupload/utils.js';
67
- import './augmentation.js';
@@ -1,136 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module image/pictureediting
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { ImageEditing } from './image/imageediting.js';
10
- import { ImageUtils } from './imageutils.js';
11
- import { downcastSourcesAttribute, upcastPicture } from './image/converters.js';
12
- /**
13
- * This plugin enables the [`<picture>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture) element support in the editor.
14
- *
15
- * * It enables the `sources` model attribute on `imageBlock` and `imageInline` model elements
16
- * (brought by {@link module:image/imageblock~ImageBlock} and {@link module:image/imageinline~ImageInline}, respectively).
17
- * * It translates the `sources` model element to the view (also: data) structure that may look as follows:
18
- *
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>
28
- *
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
- * ```
40
- *
41
- * **Note:** The value of the `sources` {@glink framework/architecture/editing-engine#changing-the-model model attribute}
42
- * in both examples equals:
43
- *
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
- * ```
58
- *
59
- * * It integrates with the {@link module:image/imageupload~ImageUpload} plugin so images uploaded in the editor
60
- * automatically render using `<picture>` if the {@glink features/images/image-upload/image-upload upload adapter}
61
- * supports image sources and provides neccessary data.
62
- *
63
- * @private
64
- */
65
- export class PictureEditing extends Plugin {
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
- static get isOfficialPlugin() {
82
- return true;
83
- }
84
- /**
85
- * @inheritDoc
86
- */
87
- afterInit() {
88
- const editor = this.editor;
89
- if (editor.plugins.has('ImageBlockEditing')) {
90
- editor.model.schema.extend('imageBlock', {
91
- allowAttributes: ['sources']
92
- });
93
- }
94
- if (editor.plugins.has('ImageInlineEditing')) {
95
- editor.model.schema.extend('imageInline', {
96
- allowAttributes: ['sources']
97
- });
98
- }
99
- this._setupConversion();
100
- this._setupImageUploadEditingIntegration();
101
- }
102
- /**
103
- * Configures conversion pipelines to support upcasting and downcasting images using the `<picture>` view element
104
- * and the model `sources` attribute.
105
- */
106
- _setupConversion() {
107
- const editor = this.editor;
108
- const conversion = editor.conversion;
109
- const imageUtils = editor.plugins.get('ImageUtils');
110
- conversion.for('upcast').add(upcastPicture(imageUtils));
111
- conversion.for('downcast').add(downcastSourcesAttribute(imageUtils));
112
- }
113
- /**
114
- * Makes it possible for uploaded images to get the `sources` model attribute and the `<picture>...</picture>`
115
- * view structure out-of-the-box if relevant data is provided along the
116
- * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing#event:uploadComplete} event.
117
- */
118
- _setupImageUploadEditingIntegration() {
119
- const editor = this.editor;
120
- if (!editor.plugins.has('ImageUploadEditing')) {
121
- return;
122
- }
123
- const imageUploadEditing = editor.plugins.get('ImageUploadEditing');
124
- this.listenTo(imageUploadEditing, 'uploadComplete', (evt, { imageElement, data }) => {
125
- const sources = data.sources;
126
- if (!sources) {
127
- return;
128
- }
129
- editor.model.change(writer => {
130
- writer.setAttributes({
131
- sources
132
- }, imageElement);
133
- });
134
- });
135
- }
136
- }
package/theme/image.css DELETED
@@ -1,143 +0,0 @@
1
- /*
2
- * Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
-
6
- .ck-content {
7
- & .image {
8
- display: table;
9
- clear: both;
10
- text-align: center;
11
-
12
- /* Make sure there is some space between the content and the image. Center image by default. */
13
- /* The first value should be equal to --ck-spacing-large variable if used in the editor context
14
- to avoid the content jumping (See https://github.com/ckeditor/ckeditor5/issues/9825). */
15
- margin: 0.9em auto;
16
-
17
- /* Make sure the caption will be displayed properly (See: https://github.com/ckeditor/ckeditor5/issues/1870). */
18
- min-width: 50px;
19
-
20
- & img {
21
- /* Prevent unnecessary margins caused by line-height (see #44). */
22
- display: block;
23
-
24
- /* Center the image if its width is smaller than the content's width. */
25
- margin: 0 auto;
26
-
27
- /* Make sure the image never exceeds the size of the parent container (ckeditor/ckeditor5-ui#67). */
28
- max-width: 100%;
29
-
30
- /* Make sure the image is never smaller than the parent container (See: https://github.com/ckeditor/ckeditor5/issues/9300). */
31
- min-width: 100%;
32
-
33
- /* Keep proportions of the block image if the height is set and the image is wider than the editor width.
34
- See https://github.com/ckeditor/ckeditor5/issues/14542. */
35
- height: auto;
36
- }
37
- }
38
-
39
- & .image-inline {
40
- /*
41
- * Normally, the .image-inline would have "display: inline-block" and "img { width: 100% }" (to follow the wrapper while resizing).
42
- * Unfortunately, together with "srcset", it gets automatically stretched up to the width of the editing root.
43
- * This strange behavior does not happen with inline-flex.
44
- */
45
- display: inline-flex;
46
-
47
- /* While being resized, don't allow the image to exceed the width of the editing root. */
48
- max-width: 100%;
49
-
50
- /* This is required by Safari to resize images in a sensible way. Without this, the browser breaks the ratio. */
51
- align-items: flex-start;
52
-
53
- /* When the picture is present it must act as a flex container to let the img resize properly */
54
- & picture {
55
- display: flex;
56
- }
57
-
58
- /* When the picture is present, it must act like a resizable img. */
59
- & picture,
60
- & img {
61
- /* This is necessary for the img to span the entire .image-inline wrapper and to resize properly. */
62
- flex-grow: 1;
63
- flex-shrink: 1;
64
-
65
- /* Prevents overflowing the editing root boundaries when an inline image is very wide. */
66
- max-width: 100%;
67
- }
68
- }
69
- }
70
-
71
- .ck.ck-editor__editable {
72
- /*
73
- * Inhertit the content styles padding of the <figcaption> in case the integration overrides `text-align: center`
74
- * of `.image` (e.g. to the left/right). This ensures the placeholder stays at the padding just like the native
75
- * caret does, and not at the edge of <figcaption>.
76
- */
77
- & .image > figcaption.ck-placeholder::before {
78
- padding-left: inherit;
79
- padding-right: inherit;
80
-
81
- /*
82
- * Make sure the image caption placeholder doesn't overflow the placeholder area.
83
- * See https://github.com/ckeditor/ckeditor5/issues/9162.
84
- */
85
- white-space: nowrap;
86
- overflow: hidden;
87
- text-overflow: ellipsis;
88
- }
89
-
90
- /*
91
- * See https://github.com/ckeditor/ckeditor5/issues/15115.
92
- */
93
- & .image {
94
- z-index: 1;
95
-
96
- /*
97
- * Make sure the selected image always stays on top of its siblings.
98
- * See https://github.com/ckeditor/ckeditor5/issues/9108.
99
- */
100
- &.ck-widget_selected {
101
- z-index: 2;
102
- }
103
- }
104
-
105
- /*
106
- * See https://github.com/ckeditor/ckeditor5/issues/15115.
107
- */
108
- & .image-inline {
109
- z-index: 1;
110
-
111
- /*
112
- * Make sure the selected inline image always stays on top of its siblings.
113
- * See https://github.com/ckeditor/ckeditor5/issues/9108.
114
- */
115
- &.ck-widget_selected {
116
- z-index: 2;
117
-
118
- /*
119
- * Make sure the native browser selection style is not displayed.
120
- * Inline image widgets have their own styles for the selected state and
121
- * leaving this up to the browser is asking for a visual collision.
122
- */
123
- & ::selection {
124
- display: none;
125
- }
126
- }
127
- }
128
-
129
- /* Keep proportions of the inline image if the height is set and the image is wider than the editor width.
130
- See https://github.com/ckeditor/ckeditor5/issues/14542. */
131
- & .image-inline img {
132
- height: auto;
133
- }
134
-
135
- /* The inline image nested in the table should have its original size if not resized.
136
- See https://github.com/ckeditor/ckeditor5/issues/9117. */
137
- & td,
138
- & th {
139
- & .image-inline img {
140
- max-width: none;
141
- }
142
- }
143
- }