@ckeditor/ckeditor5-image 40.0.0 → 40.1.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 (115) hide show
  1. package/LICENSE.md +3 -3
  2. package/build/image.js +1 -1
  3. package/package.json +3 -3
  4. package/src/augmentation.d.ts +56 -56
  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 +232 -232
  10. package/src/image/imageblockediting.d.ts +59 -58
  11. package/src/image/imageblockediting.js +153 -152
  12. package/src/image/imageediting.d.ts +30 -30
  13. package/src/image/imageediting.js +63 -63
  14. package/src/image/imageinlineediting.d.ts +60 -59
  15. package/src/image/imageinlineediting.js +177 -176
  16. package/src/image/imageloadobserver.d.ts +48 -48
  17. package/src/image/imageloadobserver.js +52 -52
  18. package/src/image/imageplaceholder.d.ts +39 -0
  19. package/src/image/imageplaceholder.js +113 -0
  20. package/src/image/imagetypecommand.d.ts +44 -44
  21. package/src/image/imagetypecommand.js +80 -80
  22. package/src/image/insertimagecommand.d.ts +66 -66
  23. package/src/image/insertimagecommand.js +120 -120
  24. package/src/image/replaceimagesourcecommand.d.ts +51 -34
  25. package/src/image/replaceimagesourcecommand.js +75 -44
  26. package/src/image/ui/utils.d.ts +25 -25
  27. package/src/image/ui/utils.js +44 -44
  28. package/src/image/utils.d.ts +64 -64
  29. package/src/image/utils.js +121 -121
  30. package/src/image.d.ts +34 -34
  31. package/src/image.js +38 -38
  32. package/src/imageblock.d.ts +33 -33
  33. package/src/imageblock.js +37 -37
  34. package/src/imagecaption/imagecaptionediting.d.ts +89 -89
  35. package/src/imagecaption/imagecaptionediting.js +225 -225
  36. package/src/imagecaption/imagecaptionui.d.ts +26 -26
  37. package/src/imagecaption/imagecaptionui.js +61 -61
  38. package/src/imagecaption/imagecaptionutils.d.ts +38 -38
  39. package/src/imagecaption/imagecaptionutils.js +62 -62
  40. package/src/imagecaption/toggleimagecaptioncommand.d.ts +66 -66
  41. package/src/imagecaption/toggleimagecaptioncommand.js +138 -138
  42. package/src/imagecaption.d.ts +26 -26
  43. package/src/imagecaption.js +30 -30
  44. package/src/imageconfig.d.ts +716 -713
  45. package/src/imageconfig.js +5 -5
  46. package/src/imageinline.d.ts +33 -33
  47. package/src/imageinline.js +37 -37
  48. package/src/imageinsert/imageinsertui.d.ts +44 -44
  49. package/src/imageinsert/imageinsertui.js +141 -141
  50. package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -61
  51. package/src/imageinsert/ui/imageinsertformrowview.js +54 -54
  52. package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -106
  53. package/src/imageinsert/ui/imageinsertpanelview.js +161 -161
  54. package/src/imageinsert/utils.d.ts +25 -25
  55. package/src/imageinsert/utils.js +58 -58
  56. package/src/imageinsert.d.ts +33 -33
  57. package/src/imageinsert.js +37 -37
  58. package/src/imageinsertviaurl.d.ts +30 -30
  59. package/src/imageinsertviaurl.js +34 -34
  60. package/src/imageresize/imageresizebuttons.d.ts +67 -67
  61. package/src/imageresize/imageresizebuttons.js +217 -217
  62. package/src/imageresize/imageresizeediting.d.ts +37 -37
  63. package/src/imageresize/imageresizeediting.js +165 -165
  64. package/src/imageresize/imageresizehandles.d.ts +31 -31
  65. package/src/imageresize/imageresizehandles.js +114 -114
  66. package/src/imageresize/resizeimagecommand.d.ts +42 -42
  67. package/src/imageresize/resizeimagecommand.js +63 -63
  68. package/src/imageresize.d.ts +27 -27
  69. package/src/imageresize.js +31 -31
  70. package/src/imagesizeattributes.d.ts +34 -34
  71. package/src/imagesizeattributes.js +142 -143
  72. package/src/imagestyle/converters.d.ts +24 -24
  73. package/src/imagestyle/converters.js +79 -79
  74. package/src/imagestyle/imagestylecommand.d.ts +68 -68
  75. package/src/imagestyle/imagestylecommand.js +107 -107
  76. package/src/imagestyle/imagestyleediting.d.ts +50 -50
  77. package/src/imagestyle/imagestyleediting.js +108 -108
  78. package/src/imagestyle/imagestyleui.d.ts +56 -56
  79. package/src/imagestyle/imagestyleui.js +192 -192
  80. package/src/imagestyle/utils.d.ts +101 -101
  81. package/src/imagestyle/utils.js +329 -329
  82. package/src/imagestyle.d.ts +32 -32
  83. package/src/imagestyle.js +36 -36
  84. package/src/imagetextalternative/imagetextalternativecommand.d.ts +34 -34
  85. package/src/imagetextalternative/imagetextalternativecommand.js +44 -44
  86. package/src/imagetextalternative/imagetextalternativeediting.d.ts +28 -28
  87. package/src/imagetextalternative/imagetextalternativeediting.js +35 -35
  88. package/src/imagetextalternative/imagetextalternativeui.d.ts +68 -68
  89. package/src/imagetextalternative/imagetextalternativeui.js +173 -173
  90. package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -72
  91. package/src/imagetextalternative/ui/textalternativeformview.js +121 -121
  92. package/src/imagetextalternative.d.ts +29 -29
  93. package/src/imagetextalternative.js +33 -33
  94. package/src/imagetoolbar.d.ts +35 -35
  95. package/src/imagetoolbar.js +57 -57
  96. package/src/imageupload/imageuploadediting.d.ts +111 -111
  97. package/src/imageupload/imageuploadediting.js +337 -337
  98. package/src/imageupload/imageuploadprogress.d.ts +42 -42
  99. package/src/imageupload/imageuploadprogress.js +211 -211
  100. package/src/imageupload/imageuploadui.d.ts +23 -23
  101. package/src/imageupload/imageuploadui.js +57 -57
  102. package/src/imageupload/uploadimagecommand.d.ts +60 -60
  103. package/src/imageupload/uploadimagecommand.js +100 -100
  104. package/src/imageupload/utils.d.ts +33 -33
  105. package/src/imageupload/utils.js +112 -112
  106. package/src/imageupload.d.ts +32 -32
  107. package/src/imageupload.js +36 -36
  108. package/src/imageutils.d.ts +125 -125
  109. package/src/imageutils.js +306 -306
  110. package/src/index.d.ts +48 -48
  111. package/src/index.js +39 -39
  112. package/src/pictureediting.d.ts +88 -88
  113. package/src/pictureediting.js +130 -130
  114. package/theme/imageplaceholder.css +10 -0
  115. package/build/image.js.map +0 -1
@@ -1,176 +1,177 @@
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/imageinlineediting
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
10
- import { UpcastWriter } from 'ckeditor5/src/engine';
11
- import { downcastImageAttribute, downcastSrcsetAttribute } from './converters';
12
- import ImageEditing from './imageediting';
13
- import ImageSizeAttributes from '../imagesizeattributes';
14
- import ImageTypeCommand from './imagetypecommand';
15
- import ImageUtils from '../imageutils';
16
- import { getImgViewElementMatcher, createInlineImageViewElement, determineImageTypeForInsertionAtSelection } from '../image/utils';
17
- /**
18
- * The image inline plugin.
19
- *
20
- * It registers:
21
- *
22
- * * `<imageInline>` as an inline element in the document schema, and allows `alt`, `src` and `srcset` attributes.
23
- * * converters for editing and data pipelines.
24
- * * {@link module:image/image/imagetypecommand~ImageTypeCommand `'imageTypeInline'`} command that converts block images into
25
- * inline images.
26
- */
27
- export default class ImageInlineEditing extends Plugin {
28
- /**
29
- * @inheritDoc
30
- */
31
- static get requires() {
32
- return [ImageEditing, ImageSizeAttributes, ImageUtils, ClipboardPipeline];
33
- }
34
- /**
35
- * @inheritDoc
36
- */
37
- static get pluginName() {
38
- return 'ImageInlineEditing';
39
- }
40
- /**
41
- * @inheritDoc
42
- */
43
- init() {
44
- const editor = this.editor;
45
- const schema = editor.model.schema;
46
- // Converters 'alt' and 'srcset' are added in 'ImageEditing' plugin.
47
- schema.register('imageInline', {
48
- inheritAllFrom: '$inlineObject',
49
- allowAttributes: ['alt', 'src', 'srcset']
50
- });
51
- // Disallow inline images in captions (for now). This is the best spot to do that because
52
- // independent packages can introduce captions (ImageCaption, TableCaption, etc.) so better this
53
- // be future-proof.
54
- schema.addChildCheck((context, childDefinition) => {
55
- if (context.endsWith('caption') && childDefinition.name === 'imageInline') {
56
- return false;
57
- }
58
- });
59
- this._setupConversion();
60
- if (editor.plugins.has('ImageBlockEditing')) {
61
- editor.commands.add('imageTypeInline', new ImageTypeCommand(this.editor, 'imageInline'));
62
- this._setupClipboardIntegration();
63
- }
64
- }
65
- /**
66
- * Configures conversion pipelines to support upcasting and downcasting
67
- * inline images (inline image widgets) and their attributes.
68
- */
69
- _setupConversion() {
70
- const editor = this.editor;
71
- const t = editor.t;
72
- const conversion = editor.conversion;
73
- const imageUtils = editor.plugins.get('ImageUtils');
74
- conversion.for('dataDowncast')
75
- .elementToElement({
76
- model: 'imageInline',
77
- view: (modelElement, { writer }) => writer.createEmptyElement('img')
78
- });
79
- conversion.for('editingDowncast')
80
- .elementToStructure({
81
- model: 'imageInline',
82
- view: (modelElement, { writer }) => imageUtils.toImageWidget(createInlineImageViewElement(writer), writer, t('image widget'))
83
- });
84
- conversion.for('downcast')
85
- .add(downcastImageAttribute(imageUtils, 'imageInline', 'src'))
86
- .add(downcastImageAttribute(imageUtils, 'imageInline', 'alt'))
87
- .add(downcastSrcsetAttribute(imageUtils, 'imageInline'));
88
- // More image related upcasts are in 'ImageEditing' plugin.
89
- conversion.for('upcast')
90
- .elementToElement({
91
- view: getImgViewElementMatcher(editor, 'imageInline'),
92
- model: (viewImage, { writer }) => writer.createElement('imageInline', viewImage.hasAttribute('src') ? { src: viewImage.getAttribute('src') } : undefined)
93
- });
94
- }
95
- /**
96
- * Integrates the plugin with the clipboard pipeline.
97
- *
98
- * Idea is that the feature should recognize the user's intent when an **block** image is
99
- * pasted or dropped. If such an image is pasted/dropped into a non-empty block
100
- * (e.g. a paragraph with some text) it gets converted into an inline image on the fly.
101
- *
102
- * We assume this is the user's intent if they decided to put their image there.
103
- *
104
- * **Note**: If a block image has a caption, it will not be converted to an inline image
105
- * to avoid the confusion. Captions are added on purpose and they should never be lost
106
- * in the clipboard pipeline.
107
- *
108
- * See the `ImageBlockEditing` for the similar integration that works in the opposite direction.
109
- *
110
- * The feature also sets image `width` and `height` attributes when pasting.
111
- */
112
- _setupClipboardIntegration() {
113
- const editor = this.editor;
114
- const model = editor.model;
115
- const editingView = editor.editing.view;
116
- const imageUtils = editor.plugins.get('ImageUtils');
117
- const clipboardPipeline = editor.plugins.get('ClipboardPipeline');
118
- this.listenTo(clipboardPipeline, 'inputTransformation', (evt, data) => {
119
- const docFragmentChildren = Array.from(data.content.getChildren());
120
- let modelRange;
121
- // Make sure only <figure class="image"></figure> elements are dropped or pasted. Otherwise, if there some other HTML
122
- // mixed up, this should be handled as a regular paste.
123
- if (!docFragmentChildren.every(imageUtils.isBlockImageView)) {
124
- return;
125
- }
126
- // When drag and dropping, data.targetRanges specifies where to drop because
127
- // this is usually a different place than the current model selection (the user
128
- // uses a drop marker to specify the drop location).
129
- if (data.targetRanges) {
130
- modelRange = editor.editing.mapper.toModelRange(data.targetRanges[0]);
131
- }
132
- // Pasting, however, always occurs at the current model selection.
133
- else {
134
- modelRange = model.document.selection.getFirstRange();
135
- }
136
- const selection = model.createSelection(modelRange);
137
- // Convert block images into inline images only when pasting or dropping into non-empty blocks
138
- // and when the block is not an object (e.g. pasting to replace another widget).
139
- if (determineImageTypeForInsertionAtSelection(model.schema, selection) === 'imageInline') {
140
- const writer = new UpcastWriter(editingView.document);
141
- // Unwrap <figure class="image"><img .../></figure> -> <img ... />
142
- // but <figure class="image"><img .../><figcaption>...</figcaption></figure> -> stays the same
143
- const inlineViewImages = docFragmentChildren.map(blockViewImage => {
144
- // If there's just one child, it can be either <img /> or <a><img></a>.
145
- // If there are other children than <img>, this means that the block image
146
- // has a caption or some other features and this kind of image should be
147
- // pasted/dropped without modifications.
148
- if (blockViewImage.childCount === 1) {
149
- // Pass the attributes which are present only in the <figure> to the <img>
150
- // (e.g. the style="width:10%" attribute applied by the ImageResize plugin).
151
- Array.from(blockViewImage.getAttributes())
152
- .forEach(attribute => writer.setAttribute(...attribute, imageUtils.findViewImgElement(blockViewImage)));
153
- return blockViewImage.getChild(0);
154
- }
155
- else {
156
- return blockViewImage;
157
- }
158
- });
159
- data.content = writer.createDocumentFragment(inlineViewImages);
160
- }
161
- });
162
- this.listenTo(clipboardPipeline, 'contentInsertion', (evt, data) => {
163
- if (data.method !== 'paste') {
164
- return;
165
- }
166
- model.change(writer => {
167
- const range = writer.createRangeIn(data.content);
168
- for (const item of range.getItems()) {
169
- if (item.is('element', 'imageInline')) {
170
- imageUtils.setImageNaturalSizeAttributes(item);
171
- }
172
- }
173
- });
174
- });
175
- }
176
- }
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/imageinlineediting
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
10
+ import { UpcastWriter } from 'ckeditor5/src/engine';
11
+ import { downcastImageAttribute, downcastSrcsetAttribute } from './converters';
12
+ import ImageEditing from './imageediting';
13
+ import ImageSizeAttributes from '../imagesizeattributes';
14
+ import ImageTypeCommand from './imagetypecommand';
15
+ import ImageUtils from '../imageutils';
16
+ import { getImgViewElementMatcher, createInlineImageViewElement, determineImageTypeForInsertionAtSelection } from './utils';
17
+ import ImagePlaceholder from './imageplaceholder';
18
+ /**
19
+ * The image inline plugin.
20
+ *
21
+ * It registers:
22
+ *
23
+ * * `<imageInline>` as an inline element in the document schema, and allows `alt`, `src` and `srcset` attributes.
24
+ * * converters for editing and data pipelines.
25
+ * * {@link module:image/image/imagetypecommand~ImageTypeCommand `'imageTypeInline'`} command that converts block images into
26
+ * inline images.
27
+ */
28
+ export default class ImageInlineEditing extends Plugin {
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get requires() {
33
+ return [ImageEditing, ImageSizeAttributes, ImageUtils, ImagePlaceholder, ClipboardPipeline];
34
+ }
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ static get pluginName() {
39
+ return 'ImageInlineEditing';
40
+ }
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ init() {
45
+ const editor = this.editor;
46
+ const schema = editor.model.schema;
47
+ // Converters 'alt' and 'srcset' are added in 'ImageEditing' plugin.
48
+ schema.register('imageInline', {
49
+ inheritAllFrom: '$inlineObject',
50
+ allowAttributes: ['alt', 'src', 'srcset']
51
+ });
52
+ // Disallow inline images in captions (for now). This is the best spot to do that because
53
+ // independent packages can introduce captions (ImageCaption, TableCaption, etc.) so better this
54
+ // be future-proof.
55
+ schema.addChildCheck((context, childDefinition) => {
56
+ if (context.endsWith('caption') && childDefinition.name === 'imageInline') {
57
+ return false;
58
+ }
59
+ });
60
+ this._setupConversion();
61
+ if (editor.plugins.has('ImageBlockEditing')) {
62
+ editor.commands.add('imageTypeInline', new ImageTypeCommand(this.editor, 'imageInline'));
63
+ this._setupClipboardIntegration();
64
+ }
65
+ }
66
+ /**
67
+ * Configures conversion pipelines to support upcasting and downcasting
68
+ * inline images (inline image widgets) and their attributes.
69
+ */
70
+ _setupConversion() {
71
+ const editor = this.editor;
72
+ const t = editor.t;
73
+ const conversion = editor.conversion;
74
+ const imageUtils = editor.plugins.get('ImageUtils');
75
+ conversion.for('dataDowncast')
76
+ .elementToElement({
77
+ model: 'imageInline',
78
+ view: (modelElement, { writer }) => writer.createEmptyElement('img')
79
+ });
80
+ conversion.for('editingDowncast')
81
+ .elementToStructure({
82
+ model: 'imageInline',
83
+ view: (modelElement, { writer }) => imageUtils.toImageWidget(createInlineImageViewElement(writer), writer, t('image widget'))
84
+ });
85
+ conversion.for('downcast')
86
+ .add(downcastImageAttribute(imageUtils, 'imageInline', 'src'))
87
+ .add(downcastImageAttribute(imageUtils, 'imageInline', 'alt'))
88
+ .add(downcastSrcsetAttribute(imageUtils, 'imageInline'));
89
+ // More image related upcasts are in 'ImageEditing' plugin.
90
+ conversion.for('upcast')
91
+ .elementToElement({
92
+ view: getImgViewElementMatcher(editor, 'imageInline'),
93
+ model: (viewImage, { writer }) => writer.createElement('imageInline', viewImage.hasAttribute('src') ? { src: viewImage.getAttribute('src') } : undefined)
94
+ });
95
+ }
96
+ /**
97
+ * Integrates the plugin with the clipboard pipeline.
98
+ *
99
+ * Idea is that the feature should recognize the user's intent when an **block** image is
100
+ * pasted or dropped. If such an image is pasted/dropped into a non-empty block
101
+ * (e.g. a paragraph with some text) it gets converted into an inline image on the fly.
102
+ *
103
+ * We assume this is the user's intent if they decided to put their image there.
104
+ *
105
+ * **Note**: If a block image has a caption, it will not be converted to an inline image
106
+ * to avoid the confusion. Captions are added on purpose and they should never be lost
107
+ * in the clipboard pipeline.
108
+ *
109
+ * See the `ImageBlockEditing` for the similar integration that works in the opposite direction.
110
+ *
111
+ * The feature also sets image `width` and `height` attributes when pasting.
112
+ */
113
+ _setupClipboardIntegration() {
114
+ const editor = this.editor;
115
+ const model = editor.model;
116
+ const editingView = editor.editing.view;
117
+ const imageUtils = editor.plugins.get('ImageUtils');
118
+ const clipboardPipeline = editor.plugins.get('ClipboardPipeline');
119
+ this.listenTo(clipboardPipeline, 'inputTransformation', (evt, data) => {
120
+ const docFragmentChildren = Array.from(data.content.getChildren());
121
+ let modelRange;
122
+ // Make sure only <figure class="image"></figure> elements are dropped or pasted. Otherwise, if there some other HTML
123
+ // mixed up, this should be handled as a regular paste.
124
+ if (!docFragmentChildren.every(imageUtils.isBlockImageView)) {
125
+ return;
126
+ }
127
+ // When drag and dropping, data.targetRanges specifies where to drop because
128
+ // this is usually a different place than the current model selection (the user
129
+ // uses a drop marker to specify the drop location).
130
+ if (data.targetRanges) {
131
+ modelRange = editor.editing.mapper.toModelRange(data.targetRanges[0]);
132
+ }
133
+ // Pasting, however, always occurs at the current model selection.
134
+ else {
135
+ modelRange = model.document.selection.getFirstRange();
136
+ }
137
+ const selection = model.createSelection(modelRange);
138
+ // Convert block images into inline images only when pasting or dropping into non-empty blocks
139
+ // and when the block is not an object (e.g. pasting to replace another widget).
140
+ if (determineImageTypeForInsertionAtSelection(model.schema, selection) === 'imageInline') {
141
+ const writer = new UpcastWriter(editingView.document);
142
+ // Unwrap <figure class="image"><img .../></figure> -> <img ... />
143
+ // but <figure class="image"><img .../><figcaption>...</figcaption></figure> -> stays the same
144
+ const inlineViewImages = docFragmentChildren.map(blockViewImage => {
145
+ // If there's just one child, it can be either <img /> or <a><img></a>.
146
+ // If there are other children than <img>, this means that the block image
147
+ // has a caption or some other features and this kind of image should be
148
+ // pasted/dropped without modifications.
149
+ if (blockViewImage.childCount === 1) {
150
+ // Pass the attributes which are present only in the <figure> to the <img>
151
+ // (e.g. the style="width:10%" attribute applied by the ImageResize plugin).
152
+ Array.from(blockViewImage.getAttributes())
153
+ .forEach(attribute => writer.setAttribute(...attribute, imageUtils.findViewImgElement(blockViewImage)));
154
+ return blockViewImage.getChild(0);
155
+ }
156
+ else {
157
+ return blockViewImage;
158
+ }
159
+ });
160
+ data.content = writer.createDocumentFragment(inlineViewImages);
161
+ }
162
+ });
163
+ this.listenTo(clipboardPipeline, 'contentInsertion', (evt, data) => {
164
+ if (data.method !== 'paste') {
165
+ return;
166
+ }
167
+ model.change(writer => {
168
+ const range = writer.createRangeIn(data.content);
169
+ for (const item of range.getItems()) {
170
+ if (item.is('element', 'imageInline')) {
171
+ imageUtils.setImageNaturalSizeAttributes(item);
172
+ }
173
+ }
174
+ });
175
+ });
176
+ }
177
+ }
@@ -1,48 +1,48 @@
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/imageloadobserver
7
- */
8
- import { Observer } from 'ckeditor5/src/engine';
9
- /**
10
- * Observes all new images added to the {@link module:engine/view/document~Document},
11
- * fires {@link module:engine/view/document~Document#event:imageLoaded} and
12
- * {@link module:engine/view/document~Document#event:layoutChanged} event every time when the new image
13
- * has been loaded.
14
- *
15
- * **Note:** This event is not fired for images that has been added to the document and rendered as `complete` (already loaded).
16
- */
17
- export default class ImageLoadObserver extends Observer {
18
- /**
19
- * @inheritDoc
20
- */
21
- observe(domRoot: HTMLElement): void;
22
- /**
23
- * @inheritDoc
24
- */
25
- stopObserving(domRoot: HTMLElement): void;
26
- /**
27
- * Fires {@link module:engine/view/document~Document#event:layoutChanged} and
28
- * {@link module:engine/view/document~Document#event:imageLoaded}
29
- * if observer {@link #isEnabled is enabled}.
30
- *
31
- * @param domEvent The DOM event.
32
- */
33
- private _fireEvents;
34
- }
35
- /**
36
- * Fired when an <img/> DOM element has been loaded in the DOM root.
37
- *
38
- * Introduced by {@link module:image/image/imageloadobserver~ImageLoadObserver}.
39
- *
40
- * @see module:image/image/imageloadobserver~ImageLoadObserver
41
- *
42
- * @eventName module:engine/view/document~Document#imageLoaded
43
- * @param data Event data.
44
- */
45
- export type ImageLoadedEvent = {
46
- name: 'imageLoaded';
47
- args: [Event];
48
- };
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/imageloadobserver
7
+ */
8
+ import { Observer } from 'ckeditor5/src/engine';
9
+ /**
10
+ * Observes all new images added to the {@link module:engine/view/document~Document},
11
+ * fires {@link module:engine/view/document~Document#event:imageLoaded} and
12
+ * {@link module:engine/view/document~Document#event:layoutChanged} event every time when the new image
13
+ * has been loaded.
14
+ *
15
+ * **Note:** This event is not fired for images that has been added to the document and rendered as `complete` (already loaded).
16
+ */
17
+ export default class ImageLoadObserver extends Observer {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ observe(domRoot: HTMLElement): void;
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ stopObserving(domRoot: HTMLElement): void;
26
+ /**
27
+ * Fires {@link module:engine/view/document~Document#event:layoutChanged} and
28
+ * {@link module:engine/view/document~Document#event:imageLoaded}
29
+ * if observer {@link #isEnabled is enabled}.
30
+ *
31
+ * @param domEvent The DOM event.
32
+ */
33
+ private _fireEvents;
34
+ }
35
+ /**
36
+ * Fired when an <img/> DOM element has been loaded in the DOM root.
37
+ *
38
+ * Introduced by {@link module:image/image/imageloadobserver~ImageLoadObserver}.
39
+ *
40
+ * @see module:image/image/imageloadobserver~ImageLoadObserver
41
+ *
42
+ * @eventName module:engine/view/document~Document#imageLoaded
43
+ * @param data Event data.
44
+ */
45
+ export type ImageLoadedEvent = {
46
+ name: 'imageLoaded';
47
+ args: [Event];
48
+ };
@@ -1,52 +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/imageloadobserver
7
- */
8
- import { Observer } from 'ckeditor5/src/engine';
9
- /**
10
- * Observes all new images added to the {@link module:engine/view/document~Document},
11
- * fires {@link module:engine/view/document~Document#event:imageLoaded} and
12
- * {@link module:engine/view/document~Document#event:layoutChanged} event every time when the new image
13
- * has been loaded.
14
- *
15
- * **Note:** This event is not fired for images that has been added to the document and rendered as `complete` (already loaded).
16
- */
17
- export default class ImageLoadObserver extends Observer {
18
- /**
19
- * @inheritDoc
20
- */
21
- observe(domRoot) {
22
- this.listenTo(domRoot, 'load', (event, domEvent) => {
23
- const domElement = domEvent.target;
24
- if (this.checkShouldIgnoreEventFromTarget(domElement)) {
25
- return;
26
- }
27
- if (domElement.tagName == 'IMG') {
28
- this._fireEvents(domEvent);
29
- }
30
- // Use capture phase for better performance (#4504).
31
- }, { useCapture: true });
32
- }
33
- /**
34
- * @inheritDoc
35
- */
36
- stopObserving(domRoot) {
37
- this.stopListening(domRoot);
38
- }
39
- /**
40
- * Fires {@link module:engine/view/document~Document#event:layoutChanged} and
41
- * {@link module:engine/view/document~Document#event:imageLoaded}
42
- * if observer {@link #isEnabled is enabled}.
43
- *
44
- * @param domEvent The DOM event.
45
- */
46
- _fireEvents(domEvent) {
47
- if (this.isEnabled) {
48
- this.document.fire('layoutChanged');
49
- this.document.fire('imageLoaded', domEvent);
50
- }
51
- }
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/imageloadobserver
7
+ */
8
+ import { Observer } from 'ckeditor5/src/engine';
9
+ /**
10
+ * Observes all new images added to the {@link module:engine/view/document~Document},
11
+ * fires {@link module:engine/view/document~Document#event:imageLoaded} and
12
+ * {@link module:engine/view/document~Document#event:layoutChanged} event every time when the new image
13
+ * has been loaded.
14
+ *
15
+ * **Note:** This event is not fired for images that has been added to the document and rendered as `complete` (already loaded).
16
+ */
17
+ export default class ImageLoadObserver extends Observer {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ observe(domRoot) {
22
+ this.listenTo(domRoot, 'load', (event, domEvent) => {
23
+ const domElement = domEvent.target;
24
+ if (this.checkShouldIgnoreEventFromTarget(domElement)) {
25
+ return;
26
+ }
27
+ if (domElement.tagName == 'IMG') {
28
+ this._fireEvents(domEvent);
29
+ }
30
+ // Use capture phase for better performance (#4504).
31
+ }, { useCapture: true });
32
+ }
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ stopObserving(domRoot) {
37
+ this.stopListening(domRoot);
38
+ }
39
+ /**
40
+ * Fires {@link module:engine/view/document~Document#event:layoutChanged} and
41
+ * {@link module:engine/view/document~Document#event:imageLoaded}
42
+ * if observer {@link #isEnabled is enabled}.
43
+ *
44
+ * @param domEvent The DOM event.
45
+ */
46
+ _fireEvents(domEvent) {
47
+ if (this.isEnabled) {
48
+ this.document.fire('layoutChanged');
49
+ this.document.fire('imageLoaded', domEvent);
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,39 @@
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/imageplaceholder
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import ImageUtils from '../imageutils';
10
+ import '../../theme/imageplaceholder.css';
11
+ /**
12
+ * Adds support for image placeholder that is automatically removed when the image is loaded.
13
+ */
14
+ export default class ImagePlaceholder extends Plugin {
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ static get requires(): readonly [typeof ImageUtils];
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ static get pluginName(): "ImagePlaceholder";
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ afterInit(): void;
27
+ /**
28
+ * Extends model schema.
29
+ */
30
+ private _setupSchema;
31
+ /**
32
+ * Registers converters.
33
+ */
34
+ private _setupConversion;
35
+ /**
36
+ * Prepares listener for image load.
37
+ */
38
+ private _setupLoadListener;
39
+ }