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

Commit 3d97b81

Browse files
committed
Other: Aligned the implementation to the new Command API (see https://github.com/ckeditor/ckeditor5-core/issues/88).
BREAKING CHANGES: The command API has been changed.
2 parents 1a6306c + b250378 commit 3d97b81

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/imageuploadcommand.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position';
1010
import ModelSelection from '@ckeditor/ckeditor5-engine/src/model/selection';
1111
import FileRepository from './filerepository';
1212
import { isImageType } from './utils';
13-
import Command from '@ckeditor/ckeditor5-core/src/command/command';
13+
import Command from '@ckeditor/ckeditor5-core/src/command';
1414

1515
/**
1616
* @module upload/imageuploadcommand
@@ -19,19 +19,19 @@ import Command from '@ckeditor/ckeditor5-core/src/command/command';
1919
/**
2020
* Image upload command.
2121
*
22-
* @extends module:core/command/command~Command
22+
* @extends module:core/command~Command
2323
*/
2424
export default class ImageUploadCommand extends Command {
2525
/**
26-
* Executes command.
26+
* Executes the command.
2727
*
28-
* @protected
28+
* @fires execute
2929
* @param {Object} options Options for executed command.
3030
* @param {File} options.file Image file to upload.
3131
* @param {module:engine/model/batch~Batch} [options.batch] Batch to collect all the change steps.
3232
* New batch will be created if this option is not set.
3333
*/
34-
_doExecute( options ) {
34+
execute( options ) {
3535
const editor = this.editor;
3636
const doc = editor.document;
3737
const batch = options.batch || doc.batch();

src/imageuploadengine.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class ImageUploadEngine extends Plugin {
4141
schema.requireAttributes( 'image', [ 'uploadId' ] );
4242

4343
// Register imageUpload command.
44-
editor.commands.set( 'imageUpload', new ImageUploadCommand( editor ) );
44+
editor.commands.add( 'imageUpload', new ImageUploadCommand( editor ) );
4545

4646
// Execute imageUpload command when image is dropped or pasted.
4747
editor.editing.view.on( 'clipboardInput', ( evt, data ) => {

tests/imageuploadcommand.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ describe( 'ImageUploadCommand', () => {
3737
} );
3838
} );
3939

40-
describe( '_doExecute', () => {
40+
describe( 'execute()', () => {
4141
it( 'should insert image', () => {
4242
const file = createNativeFileMock();
4343
setModelData( document, '<paragraph>[]foo</paragraph>' );
4444

45-
command._doExecute( { file } );
45+
command.execute( { file } );
4646

4747
const id = fileRepository.getLoader( file ).id;
4848
expect( getModelData( document ) ).to.equal( `[<image uploadId="${ id }"></image>]<paragraph>foo</paragraph>` );
@@ -52,7 +52,7 @@ describe( 'ImageUploadCommand', () => {
5252
const file = createNativeFileMock();
5353
setModelData( document, '<paragraph>foo[]</paragraph>' );
5454

55-
command._doExecute( { file } );
55+
command.execute( { file } );
5656

5757
const id = fileRepository.getLoader( file ).id;
5858
expect( getModelData( document ) ).to.equal( `<paragraph>foo</paragraph>[<image uploadId="${ id }"></image>]` );
@@ -62,7 +62,7 @@ describe( 'ImageUploadCommand', () => {
6262
const file = createNativeFileMock();
6363
setModelData( document, '<paragraph>f{}oo</paragraph>' );
6464

65-
command._doExecute( { file } );
65+
command.execute( { file } );
6666

6767
const id = fileRepository.getLoader( file ).id;
6868
expect( getModelData( document ) ).to.equal( `[<image uploadId="${ id }"></image>]<paragraph>foo</paragraph>` );
@@ -72,7 +72,7 @@ describe( 'ImageUploadCommand', () => {
7272
const file = createNativeFileMock();
7373
setModelData( document, '[<image src="image.png"></image>]' );
7474

75-
command._doExecute( { file } );
75+
command.execute( { file } );
7676

7777
const id = fileRepository.getLoader( file ).id;
7878
expect( getModelData( document ) ).to.equal( `<image src="image.png"></image>[<image uploadId="${ id }"></image>]` );
@@ -88,7 +88,7 @@ describe( 'ImageUploadCommand', () => {
8888

8989
setModelData( document, '<other>[]</other>' );
9090

91-
command._doExecute( { file } );
91+
command.execute( { file } );
9292

9393
expect( getModelData( document ) ).to.equal( '<other>[]</other>' );
9494
} );
@@ -97,7 +97,7 @@ describe( 'ImageUploadCommand', () => {
9797
const file = createNativeFileMock();
9898
file.type = 'audio/mpeg3';
9999
setModelData( document, '<paragraph>foo[]</paragraph>' );
100-
command._doExecute( { file } );
100+
command.execute( { file } );
101101

102102
expect( getModelData( document ) ).to.equal( '<paragraph>foo[]</paragraph>' );
103103
} );
@@ -109,7 +109,7 @@ describe( 'ImageUploadCommand', () => {
109109

110110
setModelData( document, '<paragraph>[]foo</paragraph>' );
111111

112-
command._doExecute( { batch, file } );
112+
command.execute( { batch, file } );
113113
const id = fileRepository.getLoader( file ).id;
114114

115115
expect( getModelData( document ) ).to.equal( `[<image uploadId="${ id }"></image>]<paragraph>foo</paragraph>` );

0 commit comments

Comments
 (0)