Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 311c48c

Browse files
authored
Merge pull request #326 from ckeditor/t/ckeditor5-core/193
Other: Make the `Clipboard` plugin a required dependency of `ImageUploadEditing`. Closes ckeditor/ckeditor5-core#193.
2 parents 74a7da5 + 78696e8 commit 311c48c

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/imageupload/imageuploadediting.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
1111
import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository';
1212
import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
13+
import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
1314
import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
1415
import env from '@ckeditor/ckeditor5-utils/src/env';
1516

@@ -27,7 +28,7 @@ export default class ImageUploadEditing extends Plugin {
2728
* @inheritDoc
2829
*/
2930
static get requires() {
30-
return [ FileRepository, Notification ];
31+
return [ FileRepository, Notification, Clipboard ];
3132
}
3233

3334
static get pluginName() {
@@ -118,31 +119,29 @@ export default class ImageUploadEditing extends Plugin {
118119
// For every image file, a new file loader is created and a placeholder image is
119120
// inserted into the content. Then, those images are uploaded once they appear in the model
120121
// (see Document#change listener below).
121-
if ( editor.plugins.has( 'Clipboard' ) ) {
122-
this.listenTo( editor.plugins.get( 'Clipboard' ), 'inputTransformation', ( evt, data ) => {
123-
const fetchableImages = Array.from( editor.editing.view.createRangeIn( data.content ) )
124-
.filter( value => isLocalImage( value.item ) && !value.item.getAttribute( 'uploadProcessed' ) )
125-
.map( value => { return { promise: fetchLocalImage( value.item ), imageElement: value.item }; } );
126-
127-
if ( !fetchableImages.length ) {
128-
return;
129-
}
122+
this.listenTo( editor.plugins.get( Clipboard ), 'inputTransformation', ( evt, data ) => {
123+
const fetchableImages = Array.from( editor.editing.view.createRangeIn( data.content ) )
124+
.filter( value => isLocalImage( value.item ) && !value.item.getAttribute( 'uploadProcessed' ) )
125+
.map( value => { return { promise: fetchLocalImage( value.item ), imageElement: value.item }; } );
130126

131-
const writer = new UpcastWriter();
127+
if ( !fetchableImages.length ) {
128+
return;
129+
}
132130

133-
for ( const fetchableImage of fetchableImages ) {
134-
// Set attribute marking that the image was processed already.
135-
writer.setAttribute( 'uploadProcessed', true, fetchableImage.imageElement );
131+
const writer = new UpcastWriter();
136132

137-
const loader = fileRepository.createLoader( fetchableImage.promise );
133+
for ( const fetchableImage of fetchableImages ) {
134+
// Set attribute marking that the image was processed already.
135+
writer.setAttribute( 'uploadProcessed', true, fetchableImage.imageElement );
138136

139-
if ( loader ) {
140-
writer.setAttribute( 'src', '', fetchableImage.imageElement );
141-
writer.setAttribute( 'uploadId', loader.id, fetchableImage.imageElement );
142-
}
137+
const loader = fileRepository.createLoader( fetchableImage.promise );
138+
139+
if ( loader ) {
140+
writer.setAttribute( 'src', '', fetchableImage.imageElement );
141+
writer.setAttribute( 'uploadId', loader.id, fetchableImage.imageElement );
143142
}
144-
} );
145-
}
143+
}
144+
} );
146145

147146
// Prevents from the browser redirecting to the dropped image.
148147
editor.editing.view.document.on( 'dragover', ( evt, data ) => {

tests/imageupload/imageuploadediting.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ describe( 'ImageUploadEditing', () => {
9595
expect( editor.commands.get( 'imageUpload' ) ).to.be.instanceOf( ImageUploadCommand );
9696
} );
9797

98-
it( 'should not crash when Clipboard plugin is not available', () => {
98+
it( 'should load Clipboard plugin', () => {
9999
return VirtualTestEditor
100100
.create( {
101101
plugins: [ ImageEditing, ImageUploadEditing, Paragraph, UndoEditing, UploadAdapterPluginMock ]
102+
} )
103+
.then( editor => {
104+
expect( editor.plugins.get( Clipboard ) ).to.be.instanceOf( Clipboard );
102105
} );
103106
} );
104107

0 commit comments

Comments
 (0)