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

Commit

Permalink
Other: Aligned the implementation to the new Command API (see https:/…
Browse files Browse the repository at this point in the history
…/github.com/ckeditor/ckeditor5-core/issues/88).

BREAKING CHANGES: The command API has been changed.
  • Loading branch information
szymonkups committed Jun 13, 2017
2 parents 1a6306c + b250378 commit 3d97b81
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/imageuploadcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position';
import ModelSelection from '@ckeditor/ckeditor5-engine/src/model/selection';
import FileRepository from './filerepository';
import { isImageType } from './utils';
import Command from '@ckeditor/ckeditor5-core/src/command/command';
import Command from '@ckeditor/ckeditor5-core/src/command';

/**
* @module upload/imageuploadcommand
Expand All @@ -19,19 +19,19 @@ import Command from '@ckeditor/ckeditor5-core/src/command/command';
/**
* Image upload command.
*
* @extends module:core/command/command~Command
* @extends module:core/command~Command
*/
export default class ImageUploadCommand extends Command {
/**
* Executes command.
* Executes the command.
*
* @protected
* @fires execute
* @param {Object} options Options for executed command.
* @param {File} options.file Image file to upload.
* @param {module:engine/model/batch~Batch} [options.batch] Batch to collect all the change steps.
* New batch will be created if this option is not set.
*/
_doExecute( options ) {
execute( options ) {
const editor = this.editor;
const doc = editor.document;
const batch = options.batch || doc.batch();
Expand Down
2 changes: 1 addition & 1 deletion src/imageuploadengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class ImageUploadEngine extends Plugin {
schema.requireAttributes( 'image', [ 'uploadId' ] );

// Register imageUpload command.
editor.commands.set( 'imageUpload', new ImageUploadCommand( editor ) );
editor.commands.add( 'imageUpload', new ImageUploadCommand( editor ) );

// Execute imageUpload command when image is dropped or pasted.
editor.editing.view.on( 'clipboardInput', ( evt, data ) => {
Expand Down
16 changes: 8 additions & 8 deletions tests/imageuploadcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ describe( 'ImageUploadCommand', () => {
} );
} );

describe( '_doExecute', () => {
describe( 'execute()', () => {
it( 'should insert image', () => {
const file = createNativeFileMock();
setModelData( document, '<paragraph>[]foo</paragraph>' );

command._doExecute( { file } );
command.execute( { file } );

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

command._doExecute( { file } );
command.execute( { file } );

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

command._doExecute( { file } );
command.execute( { file } );

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

command._doExecute( { file } );
command.execute( { file } );

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

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

command._doExecute( { file } );
command.execute( { file } );

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

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

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

command._doExecute( { batch, file } );
command.execute( { batch, file } );
const id = fileRepository.getLoader( file ).id;

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

0 comments on commit 3d97b81

Please sign in to comment.