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

Second batch of changes updating schema use to match the new API.

Piotrek Koszuliński 8 лет назад
Родитель
Сommit
7b200d9fcb

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

@@ -135,11 +135,9 @@ export default class Paragraph extends Plugin {
 			// Only empty roots are in `#_rootsToFix`. Even if root got content during `changesDone` event (because of, for example
 			// other feature), this will fire `findEmptyRoots` and remove that root from `#_rootsToFix`. So we are guaranteed
 			// to have only empty roots here.
-			const query = { name: 'paragraph', inside: [ root ] };
-			const schema = model.schema;
-
+			//
 			// If paragraph element is allowed in the root, create paragraph element.
-			if ( schema.check( query ) ) {
+			if ( model.schema.checkChild( root, 'paragraph' ) ) {
 				model.enqueueChange( batch, writer => {
 					// Remove root from `rootsToFix` here, before executing batch, to prevent infinite loops.
 					this._rootsToFix.delete( root );
@@ -297,21 +295,19 @@ function autoparagraphItems( evt, data, consumable, conversionApi ) {
 }
 
 function isParagraphable( node, context, schema, insideParagraphLikeElement ) {
-	const name = node.name || '$text';
-
 	// Node is paragraphable if it is inside paragraph like element, or...
 	// It is not allowed at this context...
-	if ( !insideParagraphLikeElement && schema.check( { name, inside: context } ) ) {
+	if ( !insideParagraphLikeElement && schema.checkChild( context, node ) ) {
 		return false;
 	}
 
 	// And paragraph is allowed in this context...
-	if ( !schema.check( { name: 'paragraph', inside: context } ) ) {
+	if ( !schema.checkChild( context, 'paragraph' ) ) {
 		return false;
 	}
 
 	// And a node would be allowed in this paragraph...
-	if ( !schema.check( { name, inside: context.concat( 'paragraph' ) } ) ) {
+	if ( !schema.checkChild( [ ...context, 'paragraph' ], node ) ) {
 		return false;
 	}
 

+ 1 - 5
packages/ckeditor5-paragraph/src/paragraphcommand.js

@@ -8,7 +8,6 @@
  */
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
-import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import first from '@ckeditor/ckeditor5-utils/src/first';
 
 /**
@@ -69,8 +68,5 @@ export default class ParagraphCommand extends Command {
 // @param {module:engine/model/schema~Schema} schema The schema of the document.
 // @returns {Boolean}
 function checkCanBecomeParagraph( block, schema ) {
-	return schema.check( {
-		name: 'paragraph',
-		inside: Position.createBefore( block )
-	} );
+	return schema.checkChild( block.parent, 'paragraph' );
 }

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

@@ -40,8 +40,8 @@ describe( 'Paragraph feature', () => {
 
 	it( 'should set proper schema rules', () => {
 		expect( model.schema.isRegistered( 'paragraph' ) ).to.be.true;
-		expect( model.schema.check( { name: 'paragraph', inside: '$root' } ) ).to.be.true;
-		expect( model.schema.check( { name: '$text', inside: 'paragraph' } ) ).to.be.true;
+		expect( model.schema.checkChild( [ '$root' ], 'paragraph' ) ).to.be.true;
+		expect( model.schema.checkChild( [ 'paragraph' ], '$text' ) ).to.be.true;
 	} );
 
 	it( 'should have a static paragraphLikeElements property', () => {
@@ -431,7 +431,7 @@ describe( 'Paragraph feature', () => {
 		} );
 
 		it( 'should not fix root which does not allow paragraph', () => {
-			model.schema.dis.extend( 'paragraph', { allowIn: '$root' } );
+			model.schema.xdisallow( 'paragraph', { allowIn: '$root' } );
 
 			model.change( writer => {
 				writer.remove( ModelRange.createIn( root ) );

+ 1 - 1
packages/ckeditor5-paragraph/tests/paragraphcommand.js

@@ -104,7 +104,7 @@ describe( 'ParagraphCommand', () => {
 		it( 'should not rename blocks which cannot become paragraphs', () => {
 			model.schema.register( 'restricted' );
 			model.schema.extend( 'restricted', { allowIn: '$root' } );
-			model.schema.dis.extend( 'paragraph', { allowIn: 'restricted' } );
+			model.schema.xdisallow( 'paragraph', { allowIn: 'restricted' } );
 
 			model.schema.register( 'fooBlock', { inheritAllFrom: '$block' } );
 			model.schema.extend( 'fooBlock', { allowIn: 'restricted' } );