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

Merge branch t/ckeditor5-engine/532

Internal: Aligned Schema API use to the new Schema API.
Piotrek Koszuliński 8 лет назад
Родитель
Сommit
35bff73642

+ 1 - 1
packages/ckeditor5-typing/src/deletecommand.js

@@ -147,7 +147,7 @@ export default class DeleteCommand extends Command {
 			return false;
 		}
 
-		if ( !model.schema.check( { name: 'paragraph', inside: limitElement.name } ) ) {
+		if ( !model.schema.checkChild( limitElement, 'paragraph' ) ) {
 			return false;
 		}
 

+ 9 - 8
packages/ckeditor5-typing/tests/deletecommand-integration.js

@@ -27,13 +27,14 @@ describe( 'DeleteCommand integration', () => {
 				editor.commands.add( 'delete', command );
 
 				// Mock paragraph feature.
-				model.schema.registerItem( 'paragraph', '$block' );
-				model.schema.allow( { name: 'paragraph', inside: '$block' } );
-
-				model.schema.registerItem( 'img', '$inline' );
-				model.schema.allow( { name: '$text', inside: 'img' } );
-
-				model.schema.objects.add( 'img' );
+				model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
+				model.schema.extend( 'paragraph', { allowIn: '$block' } );
+
+				model.schema.register( 'img', {
+					allowWhere: '$text',
+					isObject: true
+				} );
+				model.schema.extend( '$text', { allowIn: 'img' } );
 			} );
 	} );
 
@@ -125,7 +126,7 @@ describe( 'DeleteCommand integration', () => {
 
 	describe( 'with DataController.deleteContent', () => {
 		beforeEach( () => {
-			model.schema.registerItem( 'h1', '$block' );
+			model.schema.register( 'h1', { inheritAllFrom: '$block' } );
 		} );
 
 		it( 'should replace content with paragraph - if whole content is selected', () => {

+ 30 - 15
packages/ckeditor5-typing/tests/deletecommand.js

@@ -23,8 +23,8 @@ describe( 'DeleteCommand', () => {
 				const command = new DeleteCommand( editor, 'backward' );
 				editor.commands.add( 'delete', command );
 
-				model.schema.registerItem( 'paragraph', '$block' );
-				model.schema.registerItem( 'heading1', '$block' );
+				model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
+				model.schema.register( 'heading1', { inheritAllFrom: '$block' } );
 			} );
 	} );
 
@@ -157,9 +157,11 @@ describe( 'DeleteCommand', () => {
 		} );
 
 		it( 'leaves an empty paragraph after removing the whole content inside limit element', () => {
-			model.schema.registerItem( 'section', '$root' );
-			model.schema.limits.add( 'section' );
-			model.schema.allow( { name: 'section', inside: '$root' } );
+			model.schema.register( 'section', {
+				inheritAllFrom: '$root',
+				allowIn: '$root',
+				isLimit: true
+			} );
 
 			setData( model,
 				'<heading1>Foo</heading1>' +
@@ -182,13 +184,15 @@ describe( 'DeleteCommand', () => {
 		} );
 
 		it( 'leaves an empty paragraph after removing another paragraph from block element', () => {
-			model.schema.registerItem( 'section', '$block' );
-			model.schema.registerItem( 'blockQuote', '$block' );
-			model.schema.limits.add( 'section' );
-			model.schema.allow( { name: 'section', inside: '$root' } );
-			model.schema.allow( { name: 'paragraph', inside: 'section' } );
-			model.schema.allow( { name: 'blockQuote', inside: 'section' } );
-			model.schema.allow( { name: 'paragraph', inside: 'blockQuote' } );
+			model.schema.register( 'section', {
+				inheritAllFrom: '$block',
+				isLimit: true
+			} );
+			model.schema.register( 'blockQuote', { inheritAllFrom: '$block' } );
+			model.schema.extend( 'section', { allowIn: '$root' } );
+			model.schema.extend( 'paragraph', { allowIn: 'section' } );
+			model.schema.extend( 'blockQuote', { allowIn: 'section' } );
+			model.schema.extend( 'paragraph', { allowIn: 'blockQuote' } );
 
 			setData( model, '<section><blockQuote><paragraph>[]</paragraph></blockQuote></section>' );
 
@@ -197,8 +201,12 @@ describe( 'DeleteCommand', () => {
 			expect( getData( model ) ).to.equal( '<section><paragraph>[]</paragraph></section>' );
 		} );
 
-		it( 'leaves an empty paragraph after removing the whole content when root element was not added as Schema.limits', () => {
-			model.schema.limits.delete( '$root' );
+		it( 'leaves an empty paragraph after removing the whole content when root element was not added as Schema limit', () => {
+			model.schema.extend( '$root', {
+				isLimit: false
+			} );
+
+			expect( model.schema.isLimit( '$root' ) ).to.be.false;
 
 			setData( model, '<heading1>[]</heading1>' );
 
@@ -236,7 +244,14 @@ describe( 'DeleteCommand', () => {
 		} );
 
 		it( 'does not replace an element if a paragraph is not allowed in current position', () => {
-			model.schema.disallow( { name: 'paragraph', inside: '$root' } );
+			model.schema.on( 'checkChild', ( evt, args ) => {
+				const def = model.schema.getDefinition( args[ 1 ] );
+
+				if ( args[ 0 ].endsWith( '$root' ) && def.name == 'paragraph' ) {
+					evt.stop();
+					evt.return = false;
+				}
+			} );
 
 			setData( model, '<heading1>[]</heading1>' );
 

+ 2 - 2
packages/ckeditor5-typing/tests/input.js

@@ -45,7 +45,7 @@ describe( 'Input feature', () => {
 			} )
 			.then( newEditor => {
 				// Mock image feature.
-				newEditor.model.schema.registerItem( 'image', '$inline' );
+				newEditor.model.schema.register( 'image', { allowWhere: '$text' } );
 
 				buildModelConverter().for( newEditor.data.modelToView, newEditor.editing.modelToView )
 					.fromElement( 'image' )
@@ -643,7 +643,7 @@ describe( 'Input feature', () => {
 					domRoot = view.getDomRoot();
 
 					// Mock image feature.
-					newEditor.model.schema.registerItem( 'image', '$inline' );
+					newEditor.model.schema.register( 'image', { allowWhere: '$text' } );
 
 					buildModelConverter().for( newEditor.data.modelToView, newEditor.editing.modelToView )
 						.fromElement( 'image' )

+ 2 - 2
packages/ckeditor5-typing/tests/inputcommand.js

@@ -31,8 +31,8 @@ describe( 'InputCommand', () => {
 				buffer = inputCommand.buffer;
 				buffer.size = 0;
 
-				model.schema.registerItem( 'p', '$block' );
-				model.schema.registerItem( 'h1', '$block' );
+				model.schema.register( 'p', { inheritAllFrom: '$block' } );
+				model.schema.register( 'h1', { inheritAllFrom: '$block' } );
 			} );
 	} );
 

+ 1 - 1
packages/ckeditor5-typing/tests/manual/nbsp.js

@@ -20,7 +20,7 @@ ClassicEditor
 	.then( editor => {
 		window.editor = editor;
 
-		editor.model.schema.allow( { name: '$text', inside: '$root' } );
+		editor.model.schema.extend( '$text', { allowIn: '$root' } );
 
 		const editable = editor.ui.view.editableElement;