Procházet zdrojové kódy

Merge pull request #49 from ckeditor/t/48

Fix: CKFinderCommand should work when either `'link'` or `'imageInsert'` command is enabled. Closes #48.
Piotrek Koszuliński před 6 roky
rodič
revize
ba0fb52a94

+ 2 - 2
packages/ckeditor5-ckfinder/package.json

@@ -12,14 +12,14 @@
   "dependencies": {
     "@ckeditor/ckeditor5-adapter-ckfinder": "^11.0.5",
     "@ckeditor/ckeditor5-core": "^12.3.0",
+    "@ckeditor/ckeditor5-image": "^14.0.0",
+    "@ckeditor/ckeditor5-link": "^11.1.2",
     "@ckeditor/ckeditor5-ui": "^14.0.0"
   },
   "devDependencies": {
     "@ckeditor/ckeditor5-editor-classic": "^12.1.4",
     "@ckeditor/ckeditor5-clipboard": "^12.0.2",
     "@ckeditor/ckeditor5-engine": "^14.0.0",
-    "@ckeditor/ckeditor5-image": "^14.0.0",
-    "@ckeditor/ckeditor5-link": "^11.1.2",
     "@ckeditor/ckeditor5-paragraph": "^11.0.5",
     "@ckeditor/ckeditor5-utils": "^14.0.0",
     "eslint": "^5.5.0",

+ 10 - 4
packages/ckeditor5-ckfinder/src/ckfindercommand.js

@@ -13,11 +13,17 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 /**
- * The CKFinder command. It is used by the {@link module:ckfinder/ckfinderediting~CKFinderEditing ckfinder editng feature}
+ * The CKFinder command. It is used by the {@link module:ckfinder/ckfinderediting~CKFinderEditing ckfinder editing feature}
  * to open a CKFinder file browser to insert an image or a link to a file into content.
  *
  *		editor.execute( 'ckfinder' );
  *
+ * **Note:** This command uses other features to perform tasks:
+ * - To insert images the {@link module:image/image/imageinsertcommand~ImageInsertCommand 'imageInsert'} command
+ * from the {@link module:image/image~Image Image feature}.
+ * - To insert links to files the {@link module:link/linkcommand~LinkCommand 'link'} command
+ * from the {@link module:link/link~Link Link feature}.
+ *
  * @extends module:core/command~Command
  */
 export default class CKFinderCommand extends Command {
@@ -38,11 +44,11 @@ export default class CKFinderCommand extends Command {
 	 * @inheritDoc
 	 */
 	refresh() {
-		const imageCommand = this.editor.commands.get( 'imageUpload' );
+		const imageCommand = this.editor.commands.get( 'imageInsert' );
 		const linkCommand = this.editor.commands.get( 'link' );
 
 		// The CKFinder command is enabled when one of image or link command is enabled.
-		this.isEnabled = imageCommand && linkCommand && ( imageCommand.isEnabled || linkCommand.isEnabled );
+		this.isEnabled = imageCommand.isEnabled || linkCommand.isEnabled;
 	}
 
 	/**
@@ -124,7 +130,7 @@ export default class CKFinderCommand extends Command {
 }
 
 function insertImages( editor, urls ) {
-	const imageCommand = editor.commands.get( 'imageUpload' );
+	const imageCommand = editor.commands.get( 'imageInsert' );
 
 	// Check if inserting an image is actually possible - it might be possible to only insert a link.
 	if ( !imageCommand.isEnabled ) {

+ 3 - 1
packages/ckeditor5-ckfinder/src/ckfinderediting.js

@@ -8,6 +8,8 @@
  */
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+import Image from '@ckeditor/ckeditor5-image/src/image';
+import Link from '@ckeditor/ckeditor5-link/src/link';
 import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
 
 import CKFinderCommand from './ckfindercommand';
@@ -29,7 +31,7 @@ export default class CKFinderEditing extends Plugin {
 	 * @inheritDoc
 	 */
 	static get requires() {
-		return [ Notification ];
+		return [ Notification, Image, Link ];
 	}
 
 	/**

+ 24 - 0
packages/ckeditor5-ckfinder/tests/ckfindercommand.js

@@ -104,6 +104,30 @@ describe( 'CKFinderCommand', () => {
 
 			expect( command.isEnabled ).to.be.false;
 		} );
+
+		it( 'should be true when imageInsert or link command is enabled', () => {
+			setModelData( model, '<paragraph>[]</paragraph>' );
+			const insertImage = editor.commands.get( 'imageInsert' );
+			const linkCommand = editor.commands.get( 'link' );
+
+			insertImage.isEnabled = false;
+			linkCommand.isEnabled = false;
+
+			command.refresh();
+			expect( command.isEnabled ).to.be.false;
+
+			linkCommand.isEnabled = false;
+			insertImage.isEnabled = true;
+
+			command.refresh();
+			expect( command.isEnabled ).to.be.true;
+
+			linkCommand.isEnabled = true;
+			insertImage.isEnabled = false;
+
+			command.refresh();
+			expect( command.isEnabled ).to.be.true;
+		} );
 	} );
 
 	describe( 'execute()', () => {

+ 10 - 0
packages/ckeditor5-ckfinder/tests/ckfinderediting.js

@@ -6,6 +6,8 @@
 import Command from '@ckeditor/ckeditor5-core/src/command';
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
+import Image from '@ckeditor/ckeditor5-image/src/image';
+import Link from '@ckeditor/ckeditor5-link/src/link';
 import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
 import global from '@ckeditor/ckeditor5-utils/src/dom/global';
 
@@ -45,6 +47,14 @@ describe( 'CKFinderEditing', () => {
 		expect( editor.plugins.get( Notification ) ).to.instanceOf( Notification );
 	} );
 
+	it( 'should load Image plugin', () => {
+		expect( editor.plugins.get( Image ) ).to.instanceOf( Image );
+	} );
+
+	it( 'should load Link plugin', () => {
+		expect( editor.plugins.get( Link ) ).to.instanceOf( Link );
+	} );
+
 	it( 'should register command', () => {
 		const command = editor.commands.get( 'ckfinder' );