8
0
Просмотр исходного кода

Removed ClipInputCommand and fixed API docs.

Piotrek Koszuliński 9 лет назад
Родитель
Сommit
25a75cbc08

+ 27 - 17
packages/ckeditor5-clipboard/src/clipboard.js

@@ -6,7 +6,6 @@
 import Feature from '../core/feature.js';
 import Feature from '../core/feature.js';
 
 
 import ClipboardObserver from './clipboardobserver.js';
 import ClipboardObserver from './clipboardobserver.js';
-import ClipboardInputCommand from './clipboardinputcommand.js';
 
 
 import plainTextToHtml from './utils/plaintexttohtml.js';
 import plainTextToHtml from './utils/plaintexttohtml.js';
 import normalizeClipboardHtml from './utils/normalizeclipboarddata.js';
 import normalizeClipboardHtml from './utils/normalizeclipboarddata.js';
@@ -19,16 +18,18 @@ import HtmlDataProcessor from '../engine/dataprocessor/htmldataprocessor.js';
  *
  *
  * ## Clipboard Pipeline
  * ## Clipboard Pipeline
  *
  *
- * The feature creates the clipboard pipeline which allows processing clipboard content
+ * The feature creates the clipboard pipeline which allows for processing clipboard content
  * before it gets inserted into the editor. The pipeline consists of two events on which
  * before it gets inserted into the editor. The pipeline consists of two events on which
- * the features can listen to modify or totally override the default behavior.
+ * the features can listen in order to modify or totally override the default behavior.
  *
  *
  * ### On {@link engine.view.Document#paste}
  * ### On {@link engine.view.Document#paste}
  *
  *
- * 1. Get HTML or plain text from the clipboard,
- * 2. Fire {@link engine.view.Document#clipboardInput} with the clipboard data parsed to
- * a {@link engine.view.DocumentFragment view document fragment}.
- * 3. Prevent default action of the native `paste` event.
+ * The default action is to:
+ *
+ * 1. get HTML or plain text from the clipboard,
+ * 2. fire {@link engine.view.Document#clipboardInput} with the clipboard data parsed to
+ * a {@link engine.view.DocumentFragment view document fragment},
+ * 3. prevent the default action of the native `paste` event.
  *
  *
  * This action is performed by a low priority listener, so it can be overridden by a normal one.
  * This action is performed by a low priority listener, so it can be overridden by a normal one.
  * You'd only need to do this when a deeper change in pasting behavior was needed. For example,
  * You'd only need to do this when a deeper change in pasting behavior was needed. For example,
@@ -37,8 +38,8 @@ import HtmlDataProcessor from '../engine/dataprocessor/htmldataprocessor.js';
  *
  *
  * ### On {@link engine.view.Document#clipboardInput}
  * ### On {@link engine.view.Document#clipboardInput}
  *
  *
- * If the content being processed (`data.content` represented by a {@link engine.view.DocumentFragment})
- * is not empty insert it to the editor using the {@link clipboard.ClipboardInput `clipboardInput` command}.
+ * The default action is to insert the content (`data.content`, represented by a {@link engine.view.DocumentFragment})
+ * to an editor if the data is not empty.
  *
  *
  * This action is performed by a low priority listener, so it can be overridden by a normal one.
  * This action is performed by a low priority listener, so it can be overridden by a normal one.
  *
  *
@@ -49,13 +50,13 @@ import HtmlDataProcessor from '../engine/dataprocessor/htmldataprocessor.js';
  *			if ( data.content.childCount == 1 && isUrlText( data.content.getChild( 0 ) ) ) {
  *			if ( data.content.childCount == 1 && isUrlText( data.content.getChild( 0 ) ) ) {
  *				const linkUrl = data.content.getChild( 0 ).data;
  *				const linkUrl = data.content.getChild( 0 ).data;
  *
  *
- *				data.content = new ViewDocumentFragment(
+ *				data.content = new ViewDocumentFragment( [
  *					ViewElement(
  *					ViewElement(
  *						'a',
  *						'a',
  *						{ href: linkUrl },
  *						{ href: linkUrl },
  *						[ new ViewText( linkUrl ) ]
  *						[ new ViewText( linkUrl ) ]
  *					)
  *					)
- *				);
+ *				] );
  *			}
  *			}
  *		} );
  *		} );
  *
  *
@@ -70,10 +71,14 @@ export default class Clipboard extends Feature {
 		const editor = this.editor;
 		const editor = this.editor;
 		const editingView = editor.editing.view;
 		const editingView = editor.editing.view;
 
 
+		/**
+		 * Data processor used to convert pasted HTML to a view structure.
+		 *
+		 * @private
+		 * @member {engine.dataProcessor.HtmlDataProcessor} clipboard.Clipboard#_htmlDataProcessor
+		 */
 		this._htmlDataProcessor = new HtmlDataProcessor();
 		this._htmlDataProcessor = new HtmlDataProcessor();
 
 
-		editor.commands.set( 'clipboardInput', new ClipboardInputCommand( editor ) );
-
 		editingView.addObserver( ClipboardObserver );
 		editingView.addObserver( ClipboardObserver );
 
 
 		// The clipboard pipeline.
 		// The clipboard pipeline.
@@ -97,7 +102,11 @@ export default class Clipboard extends Feature {
 
 
 		this.listenTo( editingView, 'clipboardInput', ( evt, data ) => {
 		this.listenTo( editingView, 'clipboardInput', ( evt, data ) => {
 			if ( !data.content.isEmpty ) {
 			if ( !data.content.isEmpty ) {
-				editor.execute( 'clipboardInput', { content: data.content } );
+				const doc = editor.document;
+
+				doc.enqueueChanges( () => {
+					this.editor.data.insert( data.content, doc.selection );
+				} );
 			}
 			}
 		}, { priority: 'low' } );
 		}, { priority: 'low' } );
 	}
 	}
@@ -105,7 +114,8 @@ export default class Clipboard extends Feature {
 
 
 /**
 /**
  * Fired with a content which comes from the clipboard (was pasted or dropped) and
  * Fired with a content which comes from the clipboard (was pasted or dropped) and
- * should be processed in order to be inserted into the editor. It's part of the {@link clipboard.Clipboard "clipboard pipeline"}.
+ * should be processed in order to be inserted into the editor.
+ * It's part of the {@link clipboard.Clipboard "clipboard pipeline"}.
  *
  *
  * @see clipboard.ClipboardObserver
  * @see clipboard.ClipboardObserver
  * @see clipboard.Clipboard
  * @see clipboard.Clipboard
@@ -128,8 +138,8 @@ export default class Clipboard extends Feature {
  */
  */
 
 
 /**
 /**
- * Content to be inserted into the editor.
+ * Content to be inserted into the editor. It can be modified by the event listeners.
+ * Read more about the clipboard pipeline in {@link clipboard.Clipboard}.
  *
  *
- * @readonly
  * @member {engine.view.DocumentFragment} engine.view.observer.ClipboardEventData#content
  * @member {engine.view.DocumentFragment} engine.view.observer.ClipboardEventData#content
  */
  */

+ 0 - 35
packages/ckeditor5-clipboard/src/clipboardinputcommand.js

@@ -1,35 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-import Command from '../core/command/command.js';
-
-/**
- * The clipboard input command. Used by the {@link clipboard.Clipboard} feature in order to insert
- * content comming from the clipboard into the editor.
- *
- * @memberOf clipboard
- * @extends core.command.Command
- */
-export default class ClipboardInputCommand extends Command {
-	constructor( editor ) {
-		super( editor );
-	}
-
-	/**
-	 * Executes the command.
-	 *
-	 * @protected
-	 * @param {Object} options
-	 * @param {engine.view.DocumentFragment} options.content The content to paste.
-	 */
-	_doExecute( options = {} ) {
-		const doc = this.editor.document;
-		const batch = doc.batch();
-
-		doc.enqueueChanges( () => {
-			this.editor.data.insertContent( batch, doc.selection, options.content );
-		} );
-	}
-}

+ 2 - 1
packages/ckeditor5-clipboard/src/clipboardobserver.js

@@ -12,7 +12,7 @@ import DataTransfer from './datatransfer.js';
  * Note that this observer is not available by default. To make it available it needs to be added to {@link engine.view.Document}
  * Note that this observer is not available by default. To make it available it needs to be added to {@link engine.view.Document}
  * by the {@link engine.view.Document#addObserver} method.
  * by the {@link engine.view.Document#addObserver} method.
  *
  *
- * @memberOf engine.view.observer
+ * @memberOf clipboard
  * @extends engine.view.observer.DomEventObserver
  * @extends engine.view.observer.DomEventObserver
  */
  */
 export default class ClipboardObserver extends DomEventObserver {
 export default class ClipboardObserver extends DomEventObserver {
@@ -36,6 +36,7 @@ export default class ClipboardObserver extends DomEventObserver {
  *
  *
  * Note that this event is not available by default. To make it available {@link clipboard.ClipboardObserver} needs to be added
  * Note that this event is not available by default. To make it available {@link clipboard.ClipboardObserver} needs to be added
  * to {@link engine.view.Document} by the {@link engine.view.Document#addObserver} method.
  * to {@link engine.view.Document} by the {@link engine.view.Document#addObserver} method.
+ * It's done by the {@link clipboard.Clipboard} feature. If it's not loaded, it must be done manually.
  *
  *
  * @see clipboard.ClipboardObserver
  * @see clipboard.ClipboardObserver
  * @event engine.view.Document#paste
  * @event engine.view.Document#paste

+ 5 - 2
packages/ckeditor5-clipboard/src/datatransfer.js

@@ -4,14 +4,17 @@
  */
  */
 
 
 /**
 /**
- * Facade over the native [`DataTransfer`](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer).
+ * Facade over the native [`DataTransfer`](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer) object.
  *
  *
  * @memberOf clipboard
  * @memberOf clipboard
  */
  */
 export default class DataTransfer {
 export default class DataTransfer {
 	constructor( nativeDataTransfer ) {
 	constructor( nativeDataTransfer ) {
 		/**
 		/**
-		 * @private {DataTransfer}
+		 * The native DataTransfer object.
+		 *
+		 * @private
+		 * @member {DataTransfer} clipboard.DataTransfer#_native
 		 */
 		 */
 		this._native = nativeDataTransfer;
 		this._native = nativeDataTransfer;
 	}
 	}

+ 1 - 0
packages/ckeditor5-clipboard/src/utils/normalizeclipboarddata.js

@@ -6,6 +6,7 @@
 /**
 /**
  * Removes some popular browser quirks out of the clipboard data (HTML).
  * Removes some popular browser quirks out of the clipboard data (HTML).
  *
  *
+ * @function clipboard.utils.normalizeClipboardData
  * @param {String} data The HTML data to normalize.
  * @param {String} data The HTML data to normalize.
  * @returns {String} Normalized HTML.
  * @returns {String} Normalized HTML.
  */
  */

+ 1 - 0
packages/ckeditor5-clipboard/src/utils/plaintexttohtml.js

@@ -6,6 +6,7 @@
 /**
 /**
  * Converts plain text to its HTML-ized version.
  * Converts plain text to its HTML-ized version.
  *
  *
+ * @function clipboard.utils.plainTextToHtml
  * @param {String} text The plain text to convert.
  * @param {String} text The plain text to convert.
  * @returns {String} HTML generated from the plain text.
  * @returns {String} HTML generated from the plain text.
  */
  */

+ 2 - 1
packages/ckeditor5-clipboard/tests/manual/pasting.js

@@ -38,6 +38,8 @@ ClassicEditor.create( document.querySelector( '#editor' ), {
 	window.editor = editor;
 	window.editor = editor;
 
 
 	editor.editing.view.on( 'paste', ( evt, data ) => {
 	editor.editing.view.on( 'paste', ( evt, data ) => {
+		console.clear();
+
 		console.log( '----- paste -----' );
 		console.log( '----- paste -----' );
 		console.log( data );
 		console.log( data );
 		console.log( 'text/html\n', data.dataTransfer.getData( 'text/html' ) );
 		console.log( 'text/html\n', data.dataTransfer.getData( 'text/html' ) );
@@ -46,7 +48,6 @@ ClassicEditor.create( document.querySelector( '#editor' ), {
 
 
 	editor.editing.view.on( 'clipboardInput', ( evt, data ) => {
 	editor.editing.view.on( 'clipboardInput', ( evt, data ) => {
 		console.log( '----- clipboardInput -----' );
 		console.log( '----- clipboardInput -----' );
-		console.log( 'data.content\n', data.content );
 		console.log( 'stringify( data.content )\n', stringifyView( data.content ) );
 		console.log( 'stringify( data.content )\n', stringifyView( data.content ) );
 	} );
 	} );
 } )
 } )