Selaa lähdekoodia

Merge branch 'master' into t/153

Kamil Piechaczek 8 vuotta sitten
vanhempi
commit
a66d4737bb

+ 1 - 3
packages/ckeditor5-image/src/image/converters.js

@@ -7,9 +7,7 @@
  * @module image/image/converters
  */
 
-import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position';
 import ModelDocumentFragment from '@ckeditor/ckeditor5-engine/src/model/documentfragment';
-import modelWriter from '@ckeditor/ckeditor5-engine/src/model/writer';
 
 /**
  * Returns a function that converts the image view representation:
@@ -57,7 +55,7 @@ export function viewFigureToModel() {
 		data.context.pop();
 
 		// Add converted children to model image.
-		modelWriter.insert( ModelPosition.createAt( modelImage ), modelChildren );
+		conversionApi.batch.insert( modelChildren, modelImage );
 
 		// Set model image as conversion result.
 		data.output = modelImage;

+ 2 - 3
packages/ckeditor5-image/src/imagecaption/imagecaptionengine.js

@@ -9,11 +9,9 @@
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import ModelTreeWalker from '@ckeditor/ckeditor5-engine/src/model/treewalker';
-import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element';
 import ViewContainerElement from '@ckeditor/ckeditor5-engine/src/view/containerelement';
 import ViewElement from '@ckeditor/ckeditor5-engine/src/view/element';
 import viewWriter from '@ckeditor/ckeditor5-engine/src/view/writer';
-import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position';
 import ViewPosition from '@ckeditor/ckeditor5-engine/src/view/position';
 import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
 import { isImage } from '../image/utils';
@@ -176,12 +174,13 @@ function insertMissingModelCaptionElement( evt, changeType, data, batch ) {
 				// Make sure that the image does not have caption already.
 				// https://github.com/ckeditor/ckeditor5-image/issues/78
 				if ( !getCaptionFromImage( item ) ) {
-					batch.insert( ModelPosition.createAt( item, 'end' ), new ModelElement( 'caption' ) );
+					batch.appendElement( 'caption', item );
 				}
 			} );
 		}
 	}
 }
+
 // Creates a converter that converts image caption model element to view element.
 //
 // @private

+ 3 - 3
packages/ckeditor5-image/src/imagestyle/imagestylecommand.js

@@ -20,7 +20,7 @@ export default class ImageStyleCommand extends Command {
 	 * Creates an instance of the image style command. Each command instance is handling one style.
 	 *
 	 * @param {module:core/editor/editor~Editor} editor The editor instance.
-	 * @param {module:image/imagestyle/imagestyleengine~ImageStyleFormat} styles A style to be applied by this command.
+	 * @param {module:image/imagestyle/imagestyleengine~ImageStyleFormat} style A style to be applied by this command.
 	 */
 	constructor( editor, style ) {
 		super( editor );
@@ -82,9 +82,9 @@ export default class ImageStyleCommand extends Command {
 			// Default style means that there is no `imageStyle` attribute in the model.
 			// https://github.com/ckeditor/ckeditor5-image/issues/147
 			if ( this.style.isDefault ) {
-				batch.removeAttribute( imageElement, 'imageStyle' );
+				batch.removeAttribute( 'imageStyle', imageElement );
 			} else {
-				batch.setAttribute( imageElement, 'imageStyle', this.style.name );
+				batch.setAttribute( 'imageStyle', this.style.name, imageElement );
 			}
 		} );
 	}

+ 1 - 1
packages/ckeditor5-image/src/imagetextalternative/imagetextalternativecommand.js

@@ -55,7 +55,7 @@ export default class ImageTextAlternativeCommand extends Command {
 		doc.enqueueChanges( () => {
 			const batch = options.batch || doc.batch();
 
-			batch.setAttribute( imageElement, 'alt', options.newValue );
+			batch.setAttribute( 'alt', options.newValue, imageElement );
 		} );
 	}
 }

+ 14 - 13
packages/ckeditor5-image/tests/image/converters.js

@@ -22,13 +22,14 @@ import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils
 import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 describe( 'Image converters', () => {
-	let editor, document, viewDocument;
+	let editor, document, viewDocument, batch;
 
 	beforeEach( () => {
 		return VirtualTestEditor.create()
 			.then( newEditor => {
 				editor = newEditor;
 				document = editor.document;
+				batch = document.batch();
 				viewDocument = editor.editing.view;
 				const schema = document.schema;
 
@@ -138,7 +139,7 @@ describe( 'Image converters', () => {
 			document.enqueueChanges( () => {
 				const batch = document.batch();
 
-				batch.setAttribute( image, 'alt', 'foo bar' );
+				batch.setAttribute( 'alt', 'foo bar', image );
 			} );
 
 			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -153,7 +154,7 @@ describe( 'Image converters', () => {
 			document.enqueueChanges( () => {
 				const batch = document.batch();
 
-				batch.removeAttribute( image, 'alt' );
+				batch.removeAttribute( 'alt', image );
 			} );
 
 			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -168,7 +169,7 @@ describe( 'Image converters', () => {
 			document.enqueueChanges( () => {
 				const batch = document.batch();
 
-				batch.setAttribute( image, 'alt', 'baz quix' );
+				batch.setAttribute( 'alt', 'baz quix', image );
 			} );
 
 			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -187,7 +188,7 @@ describe( 'Image converters', () => {
 			document.enqueueChanges( () => {
 				const batch = document.batch();
 
-				batch.setAttribute( image, 'alt', 'baz quix' );
+				batch.setAttribute( 'alt', 'baz quix', image );
 			} );
 
 			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -230,7 +231,7 @@ describe( 'Image converters', () => {
 
 		describe( 'convertHoistableImage', () => {
 			it( 'should convert img element using already added converters if it is allowed in any point of given context #1', () => {
-				const result = dispatcher.convert( viewImg, { context: [ '$root', 'div', 'paragraph' ] } );
+				const result = dispatcher.convert( viewImg, batch, { context: [ '$root', 'div', 'paragraph' ] } );
 
 				// `result` is a model document fragment.
 				expect( result.childCount ).to.equal( 1 );
@@ -240,7 +241,7 @@ describe( 'Image converters', () => {
 			} );
 
 			it( 'should convert img element using already added converters if it is allowed in any point of given context #2', () => {
-				const result = dispatcher.convert( viewImg, { context: [ '$root', modelDiv, modelParagraph ] } );
+				const result = dispatcher.convert( viewImg, batch, { context: [ '$root', modelDiv, modelParagraph ] } );
 
 				// `result` is a model document fragment.
 				expect( result.childCount ).to.equal( 1 );
@@ -250,7 +251,7 @@ describe( 'Image converters', () => {
 			} );
 
 			it( 'should not convert img element if there is no allowed context #1', () => {
-				const result = dispatcher.convert( viewImg, { context: [ 'div', 'paragraph' ] } );
+				const result = dispatcher.convert( viewImg, batch, { context: [ 'div', 'paragraph' ] } );
 
 				// `result` is an empty model document fragment.
 				expect( result.childCount ).to.equal( 0 );
@@ -258,7 +259,7 @@ describe( 'Image converters', () => {
 			} );
 
 			it( 'should not convert img element if there is no allowed context #2', () => {
-				const result = dispatcher.convert( viewImg, { context: [ modelDiv, modelParagraph ] } );
+				const result = dispatcher.convert( viewImg, batch, { context: [ modelDiv, modelParagraph ] } );
 
 				// `result` is an empty model document fragment.
 				expect( result.childCount ).to.equal( 0 );
@@ -268,7 +269,7 @@ describe( 'Image converters', () => {
 			it( 'should not convert img element if allowed context is "above" limiting element #1', () => {
 				schema.limits.add( 'limit' );
 
-				const result = dispatcher.convert( viewImg, { context: [ '$root', 'limit', 'div', 'paragraph' ] } );
+				const result = dispatcher.convert( viewImg, batch, { context: [ '$root', 'limit', 'div', 'paragraph' ] } );
 
 				// `result` is an empty model document fragment.
 				expect( result.childCount ).to.equal( 0 );
@@ -278,7 +279,7 @@ describe( 'Image converters', () => {
 			it( 'should not convert img element if allowed context is "above" limiting element #2', () => {
 				schema.limits.add( 'limit' );
 
-				const result = dispatcher.convert( viewImg, { context: [ '$root', modelLimit, modelDiv, modelParagraph ] } );
+				const result = dispatcher.convert( viewImg, batch, { context: [ '$root', modelLimit, modelDiv, modelParagraph ] } );
 
 				// `result` is an empty model document fragment.
 				expect( result.childCount ).to.equal( 0 );
@@ -300,7 +301,7 @@ describe( 'Image converters', () => {
 				// because image is not allowed in div.
 				const viewDiv = new ViewContainerElement( 'div', null, [ 'foo', viewImg, 'bar' ] );
 
-				const result = dispatcher.convert( viewDiv, { context: [ '$root' ] } );
+				const result = dispatcher.convert( viewDiv, batch, { context: [ '$root' ] } );
 
 				// `result` is a model document fragment.
 				expect( result.childCount ).to.equal( 3 );
@@ -319,7 +320,7 @@ describe( 'Image converters', () => {
 
 				const viewDiv = new ViewContainerElement( 'p', null, [ 'foo', viewImg, 'bar' ] );
 
-				const result = dispatcher.convert( viewDiv, { context: [ '$root', 'div' ] } );
+				const result = dispatcher.convert( viewDiv, batch, { context: [ '$root', 'div' ] } );
 
 				// `result` is a model document fragment.
 				expect( result.childCount ).to.equal( 3 );

+ 7 - 7
packages/ckeditor5-image/tests/image/imageengine.js

@@ -114,7 +114,7 @@ describe( 'ImageEngine', () => {
 				document.enqueueChanges( () => {
 					const batch = document.batch();
 
-					batch.removeAttribute( image, 'srcset' );
+					batch.removeAttribute( 'srcset', image );
 				} );
 
 				expect( editor.getData() ).to.equal(
@@ -420,7 +420,7 @@ describe( 'ImageEngine', () => {
 				document.enqueueChanges( () => {
 					const batch = document.batch();
 
-					batch.setAttribute( image, 'alt', 'new text' );
+					batch.setAttribute( 'alt', 'new text', image );
 				} );
 
 				expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -435,7 +435,7 @@ describe( 'ImageEngine', () => {
 				document.enqueueChanges( () => {
 					const batch = document.batch();
 
-					batch.removeAttribute( image, 'alt' );
+					batch.removeAttribute( 'alt', image );
 				} );
 
 				expect( getViewData( viewDocument, { withoutSelection: true } ) )
@@ -453,7 +453,7 @@ describe( 'ImageEngine', () => {
 				document.enqueueChanges( () => {
 					const batch = document.batch();
 
-					batch.removeAttribute( image, 'alt' );
+					batch.removeAttribute( 'alt', image );
 				} );
 
 				expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -488,7 +488,7 @@ describe( 'ImageEngine', () => {
 				document.enqueueChanges( () => {
 					const batch = document.batch();
 
-					batch.removeAttribute( image, 'srcset' );
+					batch.removeAttribute( 'srcset', image );
 				} );
 
 				expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -520,7 +520,7 @@ describe( 'ImageEngine', () => {
 				document.enqueueChanges( () => {
 					const batch = document.batch();
 
-					batch.removeAttribute( image, 'srcset' );
+					batch.removeAttribute( 'srcset', image );
 				} );
 
 				expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -542,7 +542,7 @@ describe( 'ImageEngine', () => {
 				document.enqueueChanges( () => {
 					const batch = document.batch();
 
-					batch.removeAttribute( image, 'srcset' );
+					batch.removeAttribute( 'srcset', image );
 				} );
 
 				expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(

+ 10 - 12
packages/ckeditor5-image/tests/imagecaption/imagecaptionengine.js

@@ -15,7 +15,6 @@ import ViewPosition from '@ckeditor/ckeditor5-engine/src/view/position';
 import viewWriter from '@ckeditor/ckeditor5-engine/src/view/writer';
 import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element';
 import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
-import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position';
 
 import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
@@ -175,7 +174,7 @@ describe( 'ImageCaptionEngine', () => {
 
 				doc.enqueueChanges( () => {
 					const batch = doc.batch();
-					batch.insert( ModelPosition.createAt( caption ), 'foo bar' );
+					batch.insertText( 'foo bar', caption );
 				} );
 
 				expect( getViewData( viewDocument ) ).to.equal(
@@ -235,11 +234,10 @@ describe( 'ImageCaptionEngine', () => {
 
 	describe( 'inserting image to the document', () => {
 		it( 'should add caption element if image does not have it', () => {
-			const image = new ModelElement( 'image', { src: '', alt: '' } );
 			const batch = doc.batch();
 
 			doc.enqueueChanges( () => {
-				batch.insert( new ModelPosition( doc.getRoot(), [ 0 ] ), image );
+				batch.insertElement( 'image', { src: '', alt: '' }, doc.getRoot() );
 			} );
 
 			expect( getModelData( doc ) ).to.equal(
@@ -263,7 +261,7 @@ describe( 'ImageCaptionEngine', () => {
 			const batch = doc.batch();
 
 			doc.enqueueChanges( () => {
-				batch.insert( new ModelPosition( doc.getRoot(), [ 0 ] ), image );
+				batch.insert( image, doc.getRoot() );
 			} );
 
 			expect( getModelData( doc ) ).to.equal(
@@ -287,11 +285,11 @@ describe( 'ImageCaptionEngine', () => {
 			const batch = doc.batch();
 
 			doc.enqueueChanges( () => {
-				batch
-					// Since we are adding an empty image, this should trigger caption fixer.
-					.insert( ModelPosition.createAt( doc.getRoot() ), image )
-					// Add caption just after the image is inserted, in same batch and enqueue changes block.
-					.insert( ModelPosition.createAt( image ), caption );
+				// Since we are adding an empty image, this should trigger caption fixer.
+				batch.insert( image, doc.getRoot() );
+
+				// Add caption just after the image is inserted, in same batch and enqueue changes block.
+				batch.insert( caption, image );
 			} );
 
 			// Check whether caption fixer added redundant caption.
@@ -316,7 +314,7 @@ describe( 'ImageCaptionEngine', () => {
 			const batch = doc.batch();
 
 			doc.enqueueChanges( () => {
-				batch.setAttribute( image, 'alt', 'alt text' );
+				batch.setAttribute( 'alt', 'alt text', image );
 			} );
 
 			expect( getModelData( doc, { withoutSelection: true } ) ).to.equal(
@@ -489,7 +487,7 @@ describe( 'ImageCaptionEngine', () => {
 				doc.enqueueChanges( () => {
 					const batch = doc.batch();
 
-					batch.insert( ModelPosition.createAt( doc.getRoot() ), image );
+					batch.insert( image, doc.getRoot() );
 				} );
 
 				expect( getModelData( doc ) ).to.equal( '<image src="/foo.png"><caption></caption></image><paragraph>foo[]</paragraph>' );

+ 10 - 10
packages/ckeditor5-image/tests/imagestyle/imagestyleengine.js

@@ -135,7 +135,7 @@ describe( 'ImageStyleEngine', () => {
 			const batch = document.batch();
 
 			document.enqueueChanges( () => {
-				batch.setAttribute( image, 'imageStyle', 'sideStyle' );
+				batch.setAttribute( 'imageStyle', 'sideStyle', image );
 			} );
 
 			expect( editor.getData() ).to.equal( '<figure class="image side-class"><img src="foo.png"></figure>' );
@@ -150,7 +150,7 @@ describe( 'ImageStyleEngine', () => {
 			const batch = document.batch();
 
 			document.enqueueChanges( () => {
-				batch.setAttribute( image, 'imageStyle', null );
+				batch.setAttribute( 'imageStyle', null, image );
 			} );
 
 			expect( editor.getData() ).to.equal( '<figure class="image"><img src="foo.png"></figure>' );
@@ -165,7 +165,7 @@ describe( 'ImageStyleEngine', () => {
 			const batch = document.batch();
 
 			document.enqueueChanges( () => {
-				batch.setAttribute( image, 'imageStyle', 'sideStyle' );
+				batch.setAttribute( 'imageStyle', 'sideStyle', image );
 			} );
 
 			expect( editor.getData() ).to.equal( '<figure class="image side-class"><img src="foo.png"></figure>' );
@@ -176,7 +176,7 @@ describe( 'ImageStyleEngine', () => {
 			);
 
 			document.enqueueChanges( () => {
-				batch.setAttribute( image, 'imageStyle', 'dummyStyle' );
+				batch.setAttribute( 'imageStyle', 'dummyStyle', image );
 			} );
 
 			expect( editor.getData() ).to.equal( '<figure class="image dummy-class"><img src="foo.png"></figure>' );
@@ -197,7 +197,7 @@ describe( 'ImageStyleEngine', () => {
 			const batch = document.batch();
 
 			document.enqueueChanges( () => {
-				batch.setAttribute( image, 'imageStyle', 'sideStyle' );
+				batch.setAttribute( 'imageStyle', 'sideStyle', image );
 			} );
 
 			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -215,7 +215,7 @@ describe( 'ImageStyleEngine', () => {
 			const batch = document.batch();
 
 			document.enqueueChanges( () => {
-				batch.setAttribute( image, 'imageStyle', null );
+				batch.setAttribute( 'imageStyle', null, image );
 			} );
 
 			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -233,7 +233,7 @@ describe( 'ImageStyleEngine', () => {
 			const batch = document.batch();
 
 			document.enqueueChanges( () => {
-				batch.setAttribute( image, 'imageStyle', 'sideStyle' );
+				batch.setAttribute( 'imageStyle', 'sideStyle', image );
 			} );
 
 			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
@@ -247,7 +247,7 @@ describe( 'ImageStyleEngine', () => {
 			const batch = document.batch();
 
 			document.enqueueChanges( () => {
-				batch.setAttribute( image, 'imageStyle', 'foo' );
+				batch.setAttribute( 'imageStyle', 'foo', image );
 			} );
 
 			expect( editor.getData() ).to.equal( '<figure class="image"><img src="foo.png"></figure>' );
@@ -262,7 +262,7 @@ describe( 'ImageStyleEngine', () => {
 			const batch = document.batch();
 
 			document.enqueueChanges( () => {
-				batch.setAttribute( image, 'imageStyle', 'foo' );
+				batch.setAttribute( 'imageStyle', 'foo', image );
 			} );
 
 			expect( editor.getData() ).to.equal( '<figure class="image"><img src="foo.png"></figure>' );
@@ -277,7 +277,7 @@ describe( 'ImageStyleEngine', () => {
 			const batch = document.batch();
 
 			document.enqueueChanges( () => {
-				batch.setAttribute( image, 'imageStyle', null );
+				batch.setAttribute( 'imageStyle', null, image );
 			} );
 
 			expect( editor.getData() ).to.equal( '<figure class="image"><img src="foo.png"></figure>' );