Ver código fonte

Merge branch t/ckeditor5-engine/1555

Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Piotrek Koszuliński 7 anos atrás
pai
commit
6309b3a9a8

+ 1 - 1
packages/ckeditor5-paragraph/package.json

@@ -11,7 +11,6 @@
   ],
   "dependencies": {
     "@ckeditor/ckeditor5-core": "^11.0.1",
-    "@ckeditor/ckeditor5-engine": "^11.0.0",
     "@ckeditor/ckeditor5-ui": "^11.1.0",
     "@ckeditor/ckeditor5-utils": "^11.0.0"
   },
@@ -19,6 +18,7 @@
     "@ckeditor/ckeditor5-basic-styles": "^10.0.3",
     "@ckeditor/ckeditor5-clipboard": "^10.0.3",
     "@ckeditor/ckeditor5-editor-classic": "^11.0.1",
+    "@ckeditor/ckeditor5-engine": "^11.0.0",
     "@ckeditor/ckeditor5-enter": "^10.1.2",
     "@ckeditor/ckeditor5-heading": "^10.1.0",
     "@ckeditor/ckeditor5-link": "^10.0.4",

+ 8 - 9
packages/ckeditor5-paragraph/src/paragraph.js

@@ -10,9 +10,6 @@
 import ParagraphCommand from './paragraphcommand';
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import { SchemaContext } from '@ckeditor/ckeditor5-engine/src/model/schema';
-import Position from '@ckeditor/ckeditor5-engine/src/model/position';
-import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 
 /**
  * The paragraph feature for the editor.
@@ -49,6 +46,8 @@ export default class Paragraph extends Plugin {
 		// Handles elements not converted by plugins and checks if would be converted if
 		// we wraps them by a paragraph or changes them to a paragraph.
 		data.upcastDispatcher.on( 'element', ( evt, data, conversionApi ) => {
+			const writer = conversionApi.writer;
+
 			// When element is already consumed by higher priority converters then do nothing.
 			if ( !conversionApi.consumable.test( data.viewItem, { name: data.viewItem.name } ) ) {
 				return;
@@ -60,7 +59,7 @@ export default class Paragraph extends Plugin {
 					return;
 				}
 
-				const paragraph = conversionApi.writer.createElement( 'paragraph' );
+				const paragraph = writer.createElement( 'paragraph' );
 
 				// Find allowed parent for paragraph that we are going to insert.
 				// If current parent does not allow to insert paragraph but one of the ancestors does
@@ -73,15 +72,15 @@ export default class Paragraph extends Plugin {
 				}
 
 				// Insert paragraph in allowed position.
-				conversionApi.writer.insert( paragraph, splitResult.position );
+				writer.insert( paragraph, splitResult.position );
 
 				// Convert children to paragraph.
-				const { modelRange } = conversionApi.convertChildren( data.viewItem, Position.createAt( paragraph, 0 ) );
+				const { modelRange } = conversionApi.convertChildren( data.viewItem, writer.createPositionAt( paragraph, 0 ) );
 
 				// Output range starts before paragraph but ends inside it after last child.
 				// This is because we want to keep siblings inside the same paragraph as long as it is possible.
 				// When next node won't be allowed in a paragraph it will split this paragraph anyway.
-				data.modelRange = new Range( Position.createBefore( paragraph ), modelRange.end );
+				data.modelRange = writer.createRange( writer.createPositionBefore( paragraph ), modelRange.end );
 				data.modelCursor = data.modelRange.end;
 
 			// When element is not paragraph-like lets try to wrap it by a paragraph.
@@ -189,11 +188,11 @@ function wrapInParagraph( input, position, conversionApi ) {
 	const paragraph = conversionApi.writer.createElement( 'paragraph' );
 
 	conversionApi.writer.insert( paragraph, position );
-	return conversionApi.convertItem( input, Position.createAt( paragraph, 0 ) );
+	return conversionApi.convertItem( input, conversionApi.writer.createPositionAt( paragraph, 0 ) );
 }
 
 function isParagraphable( node, position, schema ) {
-	const context = new SchemaContext( position );
+	const context = schema.createContext( position );
 
 	// When paragraph is allowed in this context...
 	if ( !schema.checkChild( context, 'paragraph' ) ) {

+ 3 - 4
packages/ckeditor5-paragraph/tests/paragraph.js

@@ -18,7 +18,6 @@ import { upcastElementToElement, upcastElementToAttribute } from '@ckeditor/cked
 
 import ModelDocumentFragment from '@ckeditor/ckeditor5-engine/src/model/documentfragment';
 import ModelText from '@ckeditor/ckeditor5-engine/src/model/text';
-import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
 
 describe( 'Paragraph feature', () => {
 	let model, editor, doc, root;
@@ -402,7 +401,7 @@ describe( 'Paragraph feature', () => {
 			expect( editor.getData() ).to.equal( '<p>Foobar</p>' );
 
 			model.change( writer => {
-				writer.remove( ModelRange.createIn( root ) );
+				writer.remove( writer.createRangeIn( root ) );
 			} );
 
 			expect( doc.getRoot().childCount ).to.equal( 1 );
@@ -417,7 +416,7 @@ describe( 'Paragraph feature', () => {
 			} );
 
 			model.change( writer => {
-				writer.remove( ModelRange.createIn( root ) );
+				writer.remove( writer.createRangeIn( root ) );
 			} );
 
 			expect( editor.getData() ).to.equal( '' );
@@ -428,7 +427,7 @@ describe( 'Paragraph feature', () => {
 
 			model.enqueueChange( writer => {
 				removeBatch = writer.batch;
-				writer.remove( ModelRange.createIn( root ) );
+				writer.remove( writer.createRangeIn( root ) );
 
 				model.enqueueChange( writer => {
 					attributeBatch = writer.batch;

+ 7 - 5
packages/ckeditor5-paragraph/tests/paragraphcommand.js

@@ -5,8 +5,7 @@
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
 import ParagraphCommand from '../src/paragraphcommand';
-import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
-import Range from '@ckeditor/ckeditor5-engine/src/model/range';
+
 import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 describe( 'ParagraphCommand', () => {
@@ -72,7 +71,7 @@ describe( 'ParagraphCommand', () => {
 			const element = document.getRoot().getChild( 1 );
 
 			model.change( writer => {
-				writer.setSelection( Range.createIn( element ) );
+				writer.setSelection( writer.createRangeIn( element ) );
 			} );
 
 			expect( command.value ).to.be.false;
@@ -83,7 +82,7 @@ describe( 'ParagraphCommand', () => {
 			const element = document.getRoot().getChild( 1 );
 
 			model.change( writer => {
-				writer.setSelection( Range.createIn( element ) );
+				writer.setSelection( writer.createRangeIn( element ) );
 
 				expect( command.value ).to.be.true;
 				command.refresh();
@@ -185,7 +184,10 @@ describe( 'ParagraphCommand', () => {
 
 				const secondToLastHeading = root.getChild( 1 );
 				const lastHeading = root.getChild( 2 );
-				const selection = new Selection( Range.createFromParentsAndOffsets( secondToLastHeading, 0, lastHeading, 1 ) );
+				const selection = model.createSelection( model.createRange(
+					model.createPositionAt( secondToLastHeading, 0 ),
+					model.createPositionAt( lastHeading, 1 )
+				) );
 
 				command.execute( { selection } );
 				expect( getData( model ) ).to.equal(