Преглед на файлове

Aligned code with engine changes.

Oskar Wróbel преди 8 години
родител
ревизия
92d2cb7644

+ 1 - 1
packages/ckeditor5-upload/src/imageuploadbutton.js

@@ -54,7 +54,7 @@ export default class ImageUploadButton extends Plugin {
 
 			view.on( 'done', ( evt, files ) => {
 				for ( const file of Array.from( files ) ) {
-					const insertAt = findOptimalInsertionPosition( editor.document.selection );
+					const insertAt = findOptimalInsertionPosition( editor.model.document.selection );
 
 					if ( isImageType( file ) ) {
 						editor.execute( 'imageUpload', { file, insertAt } );

+ 3 - 12
packages/ckeditor5-upload/src/imageuploadcommand.js

@@ -29,18 +29,15 @@ export default class ImageUploadCommand extends Command {
 	 * If the position is not specified the image will be inserted into the current selection.
 	 * Note: You can use the {@link module:upload/utils~findOptimalInsertionPosition} function to calculate
 	 * (e.g. based on the current selection) a position which is more optimal from UX perspective.
-	 * @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.
 	 */
 	execute( options ) {
 		const editor = this.editor;
-		const doc = editor.document;
-		const batch = options.batch || doc.batch();
+		const doc = editor.model.document;
 		const file = options.file;
 		const selection = doc.selection;
 		const fileRepository = editor.plugins.get( FileRepository );
 
-		doc.enqueueChanges( () => {
+		editor.model.enqueueChange( () => {
 			const loader = fileRepository.createLoader( file );
 
 			// Do not throw when upload adapter is not set. FileRepository will log an error anyway.
@@ -60,7 +57,7 @@ export default class ImageUploadCommand extends Command {
 				insertAtSelection = doc.selection;
 			}
 
-			editor.data.insertContent( imageElement, insertAtSelection, batch );
+			editor.data.insertContent( imageElement, insertAtSelection );
 
 			// Inserting an image might've failed due to schema regulations.
 			if ( imageElement.parent ) {
@@ -69,9 +66,3 @@ export default class ImageUploadCommand extends Command {
 		} );
 	}
 }
-
-// Returns correct image insertion position.
-//
-// @param {module:engine/model/document~Document} doc
-// @returns {module:engine/model/position~Position|undefined}
-

+ 15 - 17
packages/ckeditor5-upload/src/imageuploadengine.js

@@ -32,8 +32,8 @@ export default class ImageUploadEngine extends Plugin {
 	 */
 	init() {
 		const editor = this.editor;
-		const doc = editor.document;
-		const schema = doc.schema;
+		const doc = editor.model.document;
+		const schema = editor.model.schema;
 		const fileRepository = editor.plugins.get( FileRepository );
 
 		// Setup schema to allow uploadId for images.
@@ -114,13 +114,13 @@ export default class ImageUploadEngine extends Plugin {
 	 */
 	load( loader, imageElement ) {
 		const editor = this.editor;
+		const model = editor.model;
 		const t = editor.locale.t;
-		const doc = editor.document;
 		const fileRepository = editor.plugins.get( FileRepository );
 		const notification = editor.plugins.get( Notification );
 
-		doc.enqueueChanges( () => {
-			doc.batch( 'transparent' ).setAttribute( 'uploadStatus', 'reading', imageElement );
+		model.enqueueChange( 'transparent', writer => {
+			writer.setAttribute( 'uploadStatus', 'reading', imageElement );
 		} );
 
 		loader.read()
@@ -132,15 +132,15 @@ export default class ImageUploadEngine extends Plugin {
 				viewImg.setAttribute( 'src', data );
 				editor.editing.view.render();
 
-				doc.enqueueChanges( () => {
-					doc.batch( 'transparent' ).setAttribute( 'uploadStatus', 'uploading', imageElement );
+				model.enqueueChange( 'transparent', writer => {
+					writer.setAttribute( 'uploadStatus', 'uploading', imageElement );
 				} );
 
 				return promise;
 			} )
 			.then( data => {
-				doc.enqueueChanges( () => {
-					doc.batch( 'transparent' ).setAttributes( { uploadStatus: 'complete', src: data.default }, imageElement );
+				model.enqueueChange( 'transparent', writer => {
+					writer.setAttributes( { uploadStatus: 'complete', src: data.default }, imageElement );
 
 					// Srcset attribute for responsive images support.
 					let maxWidth = 0;
@@ -163,7 +163,7 @@ export default class ImageUploadEngine extends Plugin {
 						.join( ', ' );
 
 					if ( srcsetAttribute != '' ) {
-						doc.batch( 'transparent' ).setAttribute( 'srcset', {
+						writer.setAttribute( 'srcset', {
 							data: srcsetAttribute,
 							width: maxWidth
 						}, imageElement );
@@ -184,17 +184,15 @@ export default class ImageUploadEngine extends Plugin {
 				clean();
 
 				// Permanently remove image from insertion batch.
-				doc.enqueueChanges( () => {
-					doc.batch( 'transparent' ).remove( imageElement );
+				model.enqueueChange( 'transparent', writer => {
+					writer.remove( imageElement );
 				} );
 			} );
 
 		function clean() {
-			doc.enqueueChanges( () => {
-				const batch = doc.batch( 'transparent' );
-
-				batch.removeAttribute( 'uploadId', imageElement );
-				batch.removeAttribute( 'uploadStatus', imageElement );
+			model.enqueueChange( 'transparent', writer => {
+				writer.removeAttribute( 'uploadId', imageElement );
+				writer.removeAttribute( 'uploadStatus', imageElement );
 			} );
 
 			fileRepository.destroyLoader( loader );