@ckeditor/ckeditor5-image 38.1.0 → 38.1.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 (109) hide show
  1. package/build/image.js +1 -1
  2. package/build/image.js.map +1 -0
  3. package/package.json +3 -3
  4. package/src/augmentation.d.ts +55 -55
  5. package/src/augmentation.js +5 -5
  6. package/src/autoimage.d.ts +52 -52
  7. package/src/autoimage.js +132 -132
  8. package/src/image/converters.d.ts +66 -66
  9. package/src/image/converters.js +242 -242
  10. package/src/image/imageblockediting.d.ts +55 -55
  11. package/src/image/imageblockediting.js +136 -136
  12. package/src/image/imageediting.d.ts +30 -30
  13. package/src/image/imageediting.js +74 -74
  14. package/src/image/imageinlineediting.d.ts +56 -56
  15. package/src/image/imageinlineediting.js +160 -160
  16. package/src/image/imageloadobserver.d.ts +48 -48
  17. package/src/image/imageloadobserver.js +52 -52
  18. package/src/image/imagetypecommand.d.ts +40 -40
  19. package/src/image/imagetypecommand.js +77 -77
  20. package/src/image/insertimagecommand.d.ts +66 -66
  21. package/src/image/insertimagecommand.js +120 -120
  22. package/src/image/replaceimagesourcecommand.d.ts +34 -34
  23. package/src/image/replaceimagesourcecommand.js +44 -44
  24. package/src/image/ui/utils.d.ts +25 -25
  25. package/src/image/ui/utils.js +44 -44
  26. package/src/image/utils.d.ts +52 -52
  27. package/src/image/utils.js +100 -100
  28. package/src/image.d.ts +34 -34
  29. package/src/image.js +38 -38
  30. package/src/imageblock.d.ts +33 -33
  31. package/src/imageblock.js +37 -37
  32. package/src/imagecaption/imagecaptionediting.d.ts +89 -89
  33. package/src/imagecaption/imagecaptionediting.js +225 -225
  34. package/src/imagecaption/imagecaptionui.d.ts +26 -26
  35. package/src/imagecaption/imagecaptionui.js +61 -61
  36. package/src/imagecaption/imagecaptionutils.d.ts +38 -38
  37. package/src/imagecaption/imagecaptionutils.js +62 -62
  38. package/src/imagecaption/toggleimagecaptioncommand.d.ts +66 -66
  39. package/src/imagecaption/toggleimagecaptioncommand.js +138 -138
  40. package/src/imagecaption.d.ts +26 -26
  41. package/src/imagecaption.js +30 -30
  42. package/src/imageconfig.d.ts +713 -713
  43. package/src/imageconfig.js +5 -5
  44. package/src/imageinline.d.ts +33 -33
  45. package/src/imageinline.js +37 -37
  46. package/src/imageinsert/imageinsertui.d.ts +44 -44
  47. package/src/imageinsert/imageinsertui.js +141 -141
  48. package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -61
  49. package/src/imageinsert/ui/imageinsertformrowview.js +54 -54
  50. package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -106
  51. package/src/imageinsert/ui/imageinsertpanelview.js +161 -161
  52. package/src/imageinsert/utils.d.ts +25 -25
  53. package/src/imageinsert/utils.js +58 -58
  54. package/src/imageinsert.d.ts +33 -33
  55. package/src/imageinsert.js +37 -37
  56. package/src/imageinsertviaurl.d.ts +30 -30
  57. package/src/imageinsertviaurl.js +34 -34
  58. package/src/imageresize/imageresizebuttons.d.ts +67 -67
  59. package/src/imageresize/imageresizebuttons.js +217 -217
  60. package/src/imageresize/imageresizeediting.d.ts +37 -37
  61. package/src/imageresize/imageresizeediting.js +114 -114
  62. package/src/imageresize/imageresizehandles.d.ts +30 -30
  63. package/src/imageresize/imageresizehandles.js +107 -107
  64. package/src/imageresize/resizeimagecommand.d.ts +42 -42
  65. package/src/imageresize/resizeimagecommand.js +61 -61
  66. package/src/imageresize.d.ts +27 -27
  67. package/src/imageresize.js +31 -31
  68. package/src/imagestyle/converters.d.ts +24 -24
  69. package/src/imagestyle/converters.js +79 -79
  70. package/src/imagestyle/imagestylecommand.d.ts +65 -65
  71. package/src/imagestyle/imagestylecommand.js +101 -101
  72. package/src/imagestyle/imagestyleediting.d.ts +50 -50
  73. package/src/imagestyle/imagestyleediting.js +108 -108
  74. package/src/imagestyle/imagestyleui.d.ts +56 -56
  75. package/src/imagestyle/imagestyleui.js +192 -192
  76. package/src/imagestyle/utils.d.ts +101 -101
  77. package/src/imagestyle/utils.js +329 -329
  78. package/src/imagestyle.d.ts +32 -32
  79. package/src/imagestyle.js +36 -36
  80. package/src/imagetextalternative/imagetextalternativecommand.d.ts +34 -34
  81. package/src/imagetextalternative/imagetextalternativecommand.js +44 -44
  82. package/src/imagetextalternative/imagetextalternativeediting.d.ts +28 -28
  83. package/src/imagetextalternative/imagetextalternativeediting.js +35 -35
  84. package/src/imagetextalternative/imagetextalternativeui.d.ts +68 -68
  85. package/src/imagetextalternative/imagetextalternativeui.js +173 -173
  86. package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -72
  87. package/src/imagetextalternative/ui/textalternativeformview.js +121 -121
  88. package/src/imagetextalternative.d.ts +29 -29
  89. package/src/imagetextalternative.js +33 -33
  90. package/src/imagetoolbar.d.ts +35 -35
  91. package/src/imagetoolbar.js +57 -57
  92. package/src/imageupload/imageuploadediting.d.ts +111 -111
  93. package/src/imageupload/imageuploadediting.js +335 -335
  94. package/src/imageupload/imageuploadprogress.d.ts +42 -42
  95. package/src/imageupload/imageuploadprogress.js +211 -211
  96. package/src/imageupload/imageuploadui.d.ts +23 -23
  97. package/src/imageupload/imageuploadui.js +57 -57
  98. package/src/imageupload/uploadimagecommand.d.ts +60 -60
  99. package/src/imageupload/uploadimagecommand.js +100 -100
  100. package/src/imageupload/utils.d.ts +33 -33
  101. package/src/imageupload/utils.js +112 -112
  102. package/src/imageupload.d.ts +32 -32
  103. package/src/imageupload.js +36 -36
  104. package/src/imageutils.d.ts +102 -102
  105. package/src/imageutils.js +248 -248
  106. package/src/index.d.ts +47 -47
  107. package/src/index.js +38 -38
  108. package/src/pictureediting.d.ts +88 -88
  109. package/src/pictureediting.js +130 -130
@@ -1,112 +1,112 @@
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
- import { global } from 'ckeditor5/src/utils';
6
- /**
7
- * Creates a regular expression used to test for image files.
8
- *
9
- * ```ts
10
- * const imageType = createImageTypeRegExp( [ 'png', 'jpeg', 'svg+xml', 'vnd.microsoft.icon' ] );
11
- *
12
- * console.log( 'is supported image', imageType.test( file.type ) );
13
- * ```
14
- */
15
- export function createImageTypeRegExp(types) {
16
- // Sanitize the MIME type name which may include: "+", "-" or ".".
17
- const regExpSafeNames = types.map(type => type.replace('+', '\\+'));
18
- return new RegExp(`^image\\/(${regExpSafeNames.join('|')})$`);
19
- }
20
- /**
21
- * Creates a promise that fetches the image local source (Base64 or blob) and resolves with a `File` object.
22
- *
23
- * @param image Image whose source to fetch.
24
- * @returns A promise which resolves when an image source is fetched and converted to a `File` instance.
25
- * It resolves with a `File` object. If there were any errors during file processing, the promise will be rejected.
26
- */
27
- export function fetchLocalImage(image) {
28
- return new Promise((resolve, reject) => {
29
- const imageSrc = image.getAttribute('src');
30
- // Fetch works asynchronously and so does not block browser UI when processing data.
31
- fetch(imageSrc)
32
- .then(resource => resource.blob())
33
- .then(blob => {
34
- const mimeType = getImageMimeType(blob, imageSrc);
35
- const ext = mimeType.replace('image/', '');
36
- const filename = `image.${ext}`;
37
- const file = new File([blob], filename, { type: mimeType });
38
- resolve(file);
39
- })
40
- .catch(err => {
41
- // Fetch fails only, if it can't make a request due to a network failure or if anything prevented the request
42
- // from completing, i.e. the Content Security Policy rules. It is not possible to detect the exact cause of failure,
43
- // so we are just trying the fallback solution, if general TypeError is thrown.
44
- return err && err.name === 'TypeError' ?
45
- convertLocalImageOnCanvas(imageSrc).then(resolve).catch(reject) :
46
- reject(err);
47
- });
48
- });
49
- }
50
- /**
51
- * Checks whether a given node is an image element with a local source (Base64 or blob).
52
- *
53
- * @param node The node to check.
54
- */
55
- export function isLocalImage(imageUtils, node) {
56
- if (!imageUtils.isInlineImageView(node) || !node.getAttribute('src')) {
57
- return false;
58
- }
59
- return !!node.getAttribute('src').match(/^data:image\/\w+;base64,/g) ||
60
- !!node.getAttribute('src').match(/^blob:/g);
61
- }
62
- /**
63
- * Extracts an image type based on its blob representation or its source.
64
- * @param blob Image blob representation.
65
- * @param src Image `src` attribute value.
66
- */
67
- function getImageMimeType(blob, src) {
68
- if (blob.type) {
69
- return blob.type;
70
- }
71
- else if (src.match(/data:(image\/\w+);base64/)) {
72
- return src.match(/data:(image\/\w+);base64/)[1].toLowerCase();
73
- }
74
- else {
75
- // Fallback to 'jpeg' as common extension.
76
- return 'image/jpeg';
77
- }
78
- }
79
- /**
80
- * Creates a promise that converts the image local source (Base64 or blob) to a blob using canvas and resolves
81
- * with a `File` object.
82
- * @param imageSrc Image `src` attribute value.
83
- * @returns A promise which resolves when an image source is converted to a `File` instance.
84
- * It resolves with a `File` object. If there were any errors during file processing, the promise will be rejected.
85
- */
86
- function convertLocalImageOnCanvas(imageSrc) {
87
- return getBlobFromCanvas(imageSrc).then(blob => {
88
- const mimeType = getImageMimeType(blob, imageSrc);
89
- const ext = mimeType.replace('image/', '');
90
- const filename = `image.${ext}`;
91
- return new File([blob], filename, { type: mimeType });
92
- });
93
- }
94
- /**
95
- * Creates a promise that resolves with a `Blob` object converted from the image source (Base64 or blob).
96
- * @param imageSrc Image `src` attribute value.
97
- */
98
- function getBlobFromCanvas(imageSrc) {
99
- return new Promise((resolve, reject) => {
100
- const image = global.document.createElement('img');
101
- image.addEventListener('load', () => {
102
- const canvas = global.document.createElement('canvas');
103
- canvas.width = image.width;
104
- canvas.height = image.height;
105
- const ctx = canvas.getContext('2d');
106
- ctx.drawImage(image, 0, 0);
107
- canvas.toBlob(blob => blob ? resolve(blob) : reject());
108
- });
109
- image.addEventListener('error', () => reject());
110
- image.src = imageSrc;
111
- });
112
- }
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
+ import { global } from 'ckeditor5/src/utils';
6
+ /**
7
+ * Creates a regular expression used to test for image files.
8
+ *
9
+ * ```ts
10
+ * const imageType = createImageTypeRegExp( [ 'png', 'jpeg', 'svg+xml', 'vnd.microsoft.icon' ] );
11
+ *
12
+ * console.log( 'is supported image', imageType.test( file.type ) );
13
+ * ```
14
+ */
15
+ export function createImageTypeRegExp(types) {
16
+ // Sanitize the MIME type name which may include: "+", "-" or ".".
17
+ const regExpSafeNames = types.map(type => type.replace('+', '\\+'));
18
+ return new RegExp(`^image\\/(${regExpSafeNames.join('|')})$`);
19
+ }
20
+ /**
21
+ * Creates a promise that fetches the image local source (Base64 or blob) and resolves with a `File` object.
22
+ *
23
+ * @param image Image whose source to fetch.
24
+ * @returns A promise which resolves when an image source is fetched and converted to a `File` instance.
25
+ * It resolves with a `File` object. If there were any errors during file processing, the promise will be rejected.
26
+ */
27
+ export function fetchLocalImage(image) {
28
+ return new Promise((resolve, reject) => {
29
+ const imageSrc = image.getAttribute('src');
30
+ // Fetch works asynchronously and so does not block browser UI when processing data.
31
+ fetch(imageSrc)
32
+ .then(resource => resource.blob())
33
+ .then(blob => {
34
+ const mimeType = getImageMimeType(blob, imageSrc);
35
+ const ext = mimeType.replace('image/', '');
36
+ const filename = `image.${ext}`;
37
+ const file = new File([blob], filename, { type: mimeType });
38
+ resolve(file);
39
+ })
40
+ .catch(err => {
41
+ // Fetch fails only, if it can't make a request due to a network failure or if anything prevented the request
42
+ // from completing, i.e. the Content Security Policy rules. It is not possible to detect the exact cause of failure,
43
+ // so we are just trying the fallback solution, if general TypeError is thrown.
44
+ return err && err.name === 'TypeError' ?
45
+ convertLocalImageOnCanvas(imageSrc).then(resolve).catch(reject) :
46
+ reject(err);
47
+ });
48
+ });
49
+ }
50
+ /**
51
+ * Checks whether a given node is an image element with a local source (Base64 or blob).
52
+ *
53
+ * @param node The node to check.
54
+ */
55
+ export function isLocalImage(imageUtils, node) {
56
+ if (!imageUtils.isInlineImageView(node) || !node.getAttribute('src')) {
57
+ return false;
58
+ }
59
+ return !!node.getAttribute('src').match(/^data:image\/\w+;base64,/g) ||
60
+ !!node.getAttribute('src').match(/^blob:/g);
61
+ }
62
+ /**
63
+ * Extracts an image type based on its blob representation or its source.
64
+ * @param blob Image blob representation.
65
+ * @param src Image `src` attribute value.
66
+ */
67
+ function getImageMimeType(blob, src) {
68
+ if (blob.type) {
69
+ return blob.type;
70
+ }
71
+ else if (src.match(/data:(image\/\w+);base64/)) {
72
+ return src.match(/data:(image\/\w+);base64/)[1].toLowerCase();
73
+ }
74
+ else {
75
+ // Fallback to 'jpeg' as common extension.
76
+ return 'image/jpeg';
77
+ }
78
+ }
79
+ /**
80
+ * Creates a promise that converts the image local source (Base64 or blob) to a blob using canvas and resolves
81
+ * with a `File` object.
82
+ * @param imageSrc Image `src` attribute value.
83
+ * @returns A promise which resolves when an image source is converted to a `File` instance.
84
+ * It resolves with a `File` object. If there were any errors during file processing, the promise will be rejected.
85
+ */
86
+ function convertLocalImageOnCanvas(imageSrc) {
87
+ return getBlobFromCanvas(imageSrc).then(blob => {
88
+ const mimeType = getImageMimeType(blob, imageSrc);
89
+ const ext = mimeType.replace('image/', '');
90
+ const filename = `image.${ext}`;
91
+ return new File([blob], filename, { type: mimeType });
92
+ });
93
+ }
94
+ /**
95
+ * Creates a promise that resolves with a `Blob` object converted from the image source (Base64 or blob).
96
+ * @param imageSrc Image `src` attribute value.
97
+ */
98
+ function getBlobFromCanvas(imageSrc) {
99
+ return new Promise((resolve, reject) => {
100
+ const image = global.document.createElement('img');
101
+ image.addEventListener('load', () => {
102
+ const canvas = global.document.createElement('canvas');
103
+ canvas.width = image.width;
104
+ canvas.height = image.height;
105
+ const ctx = canvas.getContext('2d');
106
+ ctx.drawImage(image, 0, 0);
107
+ canvas.toBlob(blob => blob ? resolve(blob) : reject());
108
+ });
109
+ image.addEventListener('error', () => reject());
110
+ image.src = imageSrc;
111
+ });
112
+ }
@@ -1,32 +1,32 @@
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/imageupload
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import ImageUploadUI from './imageupload/imageuploadui';
10
- import ImageUploadProgress from './imageupload/imageuploadprogress';
11
- import ImageUploadEditing from './imageupload/imageuploadediting';
12
- /**
13
- * The image upload plugin.
14
- *
15
- * For a detailed overview, check the {@glink features/images/image-upload/image-upload image upload feature} documentation.
16
- *
17
- * This plugin does not do anything directly, but it loads a set of specific plugins to enable image uploading:
18
- *
19
- * * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing},
20
- * * {@link module:image/imageupload/imageuploadui~ImageUploadUI},
21
- * * {@link module:image/imageupload/imageuploadprogress~ImageUploadProgress}.
22
- */
23
- export default class ImageUpload extends Plugin {
24
- /**
25
- * @inheritDoc
26
- */
27
- static get pluginName(): "ImageUpload";
28
- /**
29
- * @inheritDoc
30
- */
31
- static get requires(): readonly [typeof ImageUploadEditing, typeof ImageUploadUI, typeof ImageUploadProgress];
32
- }
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/imageupload
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import ImageUploadUI from './imageupload/imageuploadui';
10
+ import ImageUploadProgress from './imageupload/imageuploadprogress';
11
+ import ImageUploadEditing from './imageupload/imageuploadediting';
12
+ /**
13
+ * The image upload plugin.
14
+ *
15
+ * For a detailed overview, check the {@glink features/images/image-upload/image-upload image upload feature} documentation.
16
+ *
17
+ * This plugin does not do anything directly, but it loads a set of specific plugins to enable image uploading:
18
+ *
19
+ * * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing},
20
+ * * {@link module:image/imageupload/imageuploadui~ImageUploadUI},
21
+ * * {@link module:image/imageupload/imageuploadprogress~ImageUploadProgress}.
22
+ */
23
+ export default class ImageUpload extends Plugin {
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName(): "ImageUpload";
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get requires(): readonly [typeof ImageUploadEditing, typeof ImageUploadUI, typeof ImageUploadProgress];
32
+ }
@@ -1,36 +1,36 @@
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/imageupload
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import ImageUploadUI from './imageupload/imageuploadui';
10
- import ImageUploadProgress from './imageupload/imageuploadprogress';
11
- import ImageUploadEditing from './imageupload/imageuploadediting';
12
- /**
13
- * The image upload plugin.
14
- *
15
- * For a detailed overview, check the {@glink features/images/image-upload/image-upload image upload feature} documentation.
16
- *
17
- * This plugin does not do anything directly, but it loads a set of specific plugins to enable image uploading:
18
- *
19
- * * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing},
20
- * * {@link module:image/imageupload/imageuploadui~ImageUploadUI},
21
- * * {@link module:image/imageupload/imageuploadprogress~ImageUploadProgress}.
22
- */
23
- export default class ImageUpload extends Plugin {
24
- /**
25
- * @inheritDoc
26
- */
27
- static get pluginName() {
28
- return 'ImageUpload';
29
- }
30
- /**
31
- * @inheritDoc
32
- */
33
- static get requires() {
34
- return [ImageUploadEditing, ImageUploadUI, ImageUploadProgress];
35
- }
36
- }
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/imageupload
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import ImageUploadUI from './imageupload/imageuploadui';
10
+ import ImageUploadProgress from './imageupload/imageuploadprogress';
11
+ import ImageUploadEditing from './imageupload/imageuploadediting';
12
+ /**
13
+ * The image upload plugin.
14
+ *
15
+ * For a detailed overview, check the {@glink features/images/image-upload/image-upload image upload feature} documentation.
16
+ *
17
+ * This plugin does not do anything directly, but it loads a set of specific plugins to enable image uploading:
18
+ *
19
+ * * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing},
20
+ * * {@link module:image/imageupload/imageuploadui~ImageUploadUI},
21
+ * * {@link module:image/imageupload/imageuploadprogress~ImageUploadProgress}.
22
+ */
23
+ export default class ImageUpload extends Plugin {
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName() {
28
+ return 'ImageUpload';
29
+ }
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ static get requires() {
34
+ return [ImageUploadEditing, ImageUploadUI, ImageUploadProgress];
35
+ }
36
+ }
@@ -1,102 +1,102 @@
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/imageutils
7
- */
8
- import type { Element, ViewElement, DocumentSelection, ViewDocumentSelection, Selection, ViewSelection, DowncastWriter, Position } from 'ckeditor5/src/engine';
9
- import { Plugin } from 'ckeditor5/src/core';
10
- /**
11
- * A set of helpers related to images.
12
- */
13
- export default class ImageUtils extends Plugin {
14
- /**
15
- * @inheritDoc
16
- */
17
- static get pluginName(): "ImageUtils";
18
- /**
19
- * Checks if the provided model element is an `image` or `imageInline`.
20
- */
21
- isImage(modelElement?: Element | null): modelElement is Element & {
22
- name: 'imageInline' | 'imageBlock';
23
- };
24
- /**
25
- * Checks if the provided view element represents an inline image.
26
- *
27
- * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
28
- */
29
- isInlineImageView(element?: ViewElement | null): boolean;
30
- /**
31
- * Checks if the provided view element represents a block image.
32
- *
33
- * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
34
- */
35
- isBlockImageView(element?: ViewElement | null): boolean;
36
- /**
37
- * Handles inserting single file. This method unifies image insertion using {@link module:widget/utils~findOptimalInsertionRange}
38
- * method.
39
- *
40
- * ```ts
41
- * const imageUtils = editor.plugins.get( 'ImageUtils' );
42
- *
43
- * imageUtils.insertImage( { src: 'path/to/image.jpg' } );
44
- * ```
45
- *
46
- * @param attributes Attributes of the inserted image.
47
- * This method filters out the attributes which are disallowed by the {@link module:engine/model/schema~Schema}.
48
- * @param selectable Place to insert the image. If not specified,
49
- * the {@link module:widget/utils~findOptimalInsertionRange} logic will be applied for the block images
50
- * and `model.document.selection` for the inline images.
51
- *
52
- * **Note**: If `selectable` is passed, this helper will not be able to set selection attributes (such as `linkHref`)
53
- * and apply them to the new image. In this case, make sure all selection attributes are passed in `attributes`.
54
- *
55
- * @param imageType Image type of inserted image. If not specified,
56
- * it will be determined automatically depending of editor config or place of the insertion.
57
- * @return The inserted model image element.
58
- */
59
- insertImage(attributes?: Record<string, unknown>, selectable?: Selection | Position | null, imageType?: ('imageBlock' | 'imageInline' | null)): Element | null;
60
- /**
61
- * Returns an image widget editing view element if one is selected or is among the selection's ancestors.
62
- */
63
- getClosestSelectedImageWidget(selection: ViewSelection | ViewDocumentSelection): ViewElement | null;
64
- /**
65
- * Returns a image model element if one is selected or is among the selection's ancestors.
66
- */
67
- getClosestSelectedImageElement(selection: Selection | DocumentSelection): Element | null;
68
- /**
69
- * Checks if image can be inserted at current model selection.
70
- *
71
- * @internal
72
- */
73
- isImageAllowed(): boolean;
74
- /**
75
- * Converts a given {@link module:engine/view/element~Element} to an image widget:
76
- * * Adds a {@link module:engine/view/element~Element#_setCustomProperty custom property} allowing to recognize the image widget
77
- * element.
78
- * * Calls the {@link module:widget/utils~toWidget} function with the proper element's label creator.
79
- *
80
- * @param writer An instance of the view writer.
81
- * @param label The element's label. It will be concatenated with the image `alt` attribute if one is present.
82
- */
83
- toImageWidget(viewElement: ViewElement, writer: DowncastWriter, label: string): ViewElement;
84
- /**
85
- * Checks if a given view element is an image widget.
86
- */
87
- protected isImageWidget(viewElement: ViewElement): boolean;
88
- /**
89
- * Checks if the provided model element is an `image`.
90
- */
91
- isBlockImage(modelElement?: Element | null): boolean;
92
- /**
93
- * Checks if the provided model element is an `imageInline`.
94
- */
95
- isInlineImage(modelElement?: Element | null): boolean;
96
- /**
97
- * Get the view `<img>` from another view element, e.g. a widget (`<figure class="image">`), a link (`<a>`).
98
- *
99
- * The `<img>` can be located deep in other elements, so this helper performs a deep tree search.
100
- */
101
- findViewImgElement(figureView: ViewElement): ViewElement | undefined;
102
- }
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/imageutils
7
+ */
8
+ import type { Element, ViewElement, DocumentSelection, ViewDocumentSelection, Selection, ViewSelection, DowncastWriter, Position } from 'ckeditor5/src/engine';
9
+ import { Plugin } from 'ckeditor5/src/core';
10
+ /**
11
+ * A set of helpers related to images.
12
+ */
13
+ export default class ImageUtils extends Plugin {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get pluginName(): "ImageUtils";
18
+ /**
19
+ * Checks if the provided model element is an `image` or `imageInline`.
20
+ */
21
+ isImage(modelElement?: Element | null): modelElement is Element & {
22
+ name: 'imageInline' | 'imageBlock';
23
+ };
24
+ /**
25
+ * Checks if the provided view element represents an inline image.
26
+ *
27
+ * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
28
+ */
29
+ isInlineImageView(element?: ViewElement | null): boolean;
30
+ /**
31
+ * Checks if the provided view element represents a block image.
32
+ *
33
+ * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
34
+ */
35
+ isBlockImageView(element?: ViewElement | null): boolean;
36
+ /**
37
+ * Handles inserting single file. This method unifies image insertion using {@link module:widget/utils~findOptimalInsertionRange}
38
+ * method.
39
+ *
40
+ * ```ts
41
+ * const imageUtils = editor.plugins.get( 'ImageUtils' );
42
+ *
43
+ * imageUtils.insertImage( { src: 'path/to/image.jpg' } );
44
+ * ```
45
+ *
46
+ * @param attributes Attributes of the inserted image.
47
+ * This method filters out the attributes which are disallowed by the {@link module:engine/model/schema~Schema}.
48
+ * @param selectable Place to insert the image. If not specified,
49
+ * the {@link module:widget/utils~findOptimalInsertionRange} logic will be applied for the block images
50
+ * and `model.document.selection` for the inline images.
51
+ *
52
+ * **Note**: If `selectable` is passed, this helper will not be able to set selection attributes (such as `linkHref`)
53
+ * and apply them to the new image. In this case, make sure all selection attributes are passed in `attributes`.
54
+ *
55
+ * @param imageType Image type of inserted image. If not specified,
56
+ * it will be determined automatically depending of editor config or place of the insertion.
57
+ * @return The inserted model image element.
58
+ */
59
+ insertImage(attributes?: Record<string, unknown>, selectable?: Selection | Position | null, imageType?: ('imageBlock' | 'imageInline' | null)): Element | null;
60
+ /**
61
+ * Returns an image widget editing view element if one is selected or is among the selection's ancestors.
62
+ */
63
+ getClosestSelectedImageWidget(selection: ViewSelection | ViewDocumentSelection): ViewElement | null;
64
+ /**
65
+ * Returns a image model element if one is selected or is among the selection's ancestors.
66
+ */
67
+ getClosestSelectedImageElement(selection: Selection | DocumentSelection): Element | null;
68
+ /**
69
+ * Checks if image can be inserted at current model selection.
70
+ *
71
+ * @internal
72
+ */
73
+ isImageAllowed(): boolean;
74
+ /**
75
+ * Converts a given {@link module:engine/view/element~Element} to an image widget:
76
+ * * Adds a {@link module:engine/view/element~Element#_setCustomProperty custom property} allowing to recognize the image widget
77
+ * element.
78
+ * * Calls the {@link module:widget/utils~toWidget} function with the proper element's label creator.
79
+ *
80
+ * @param writer An instance of the view writer.
81
+ * @param label The element's label. It will be concatenated with the image `alt` attribute if one is present.
82
+ */
83
+ toImageWidget(viewElement: ViewElement, writer: DowncastWriter, label: string): ViewElement;
84
+ /**
85
+ * Checks if a given view element is an image widget.
86
+ */
87
+ protected isImageWidget(viewElement: ViewElement): boolean;
88
+ /**
89
+ * Checks if the provided model element is an `image`.
90
+ */
91
+ isBlockImage(modelElement?: Element | null): boolean;
92
+ /**
93
+ * Checks if the provided model element is an `imageInline`.
94
+ */
95
+ isInlineImage(modelElement?: Element | null): boolean;
96
+ /**
97
+ * Get the view `<img>` from another view element, e.g. a widget (`<figure class="image">`), a link (`<a>`).
98
+ *
99
+ * The `<img>` can be located deep in other elements, so this helper performs a deep tree search.
100
+ */
101
+ findViewImgElement(figureView: ViewElement): ViewElement | undefined;
102
+ }