Przeglądaj źródła

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

Piotrek Koszuliński 8 lat temu
rodzic
commit
8440bdc7fc

+ 2 - 4
packages/ckeditor5-basic-styles/src/boldengine.js

@@ -31,10 +31,8 @@ export default class BoldEngine extends Plugin {
 		const data = editor.data;
 		const data = editor.data;
 		const editing = editor.editing;
 		const editing = editor.editing;
 
 
-		// Allow bold attribute on all inline nodes.
-		editor.model.schema.allow( { name: '$inline', attributes: BOLD, inside: '$block' } );
-		// Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
-		editor.model.schema.allow( { name: '$inline', attributes: BOLD, inside: '$clipboardHolder' } );
+		// Allow bold attribute on text nodes.
+		editor.model.schema.extend( '$text', { allowAttributes: BOLD } );
 
 
 		// Build converter from model to view for data and editing pipelines.
 		// Build converter from model to view for data and editing pipelines.
 		buildModelConverter().for( data.modelToView, editing.modelToView )
 		buildModelConverter().for( data.modelToView, editing.modelToView )

+ 2 - 4
packages/ckeditor5-basic-styles/src/codeengine.js

@@ -31,10 +31,8 @@ export default class CodeEngine extends Plugin {
 		const data = editor.data;
 		const data = editor.data;
 		const editing = editor.editing;
 		const editing = editor.editing;
 
 
-		// Allow code attribute on all inline nodes.
-		editor.model.schema.allow( { name: '$inline', attributes: CODE, inside: '$block' } );
-		// Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
-		editor.model.schema.allow( { name: '$inline', attributes: CODE, inside: '$clipboardHolder' } );
+		// Allow code attribute on text nodes.
+		editor.model.schema.extend( '$text', { allowAttributes: CODE } );
 
 
 		// Build converter from model to view for data and editing pipelines.
 		// Build converter from model to view for data and editing pipelines.
 		buildModelConverter().for( data.modelToView, editing.modelToView )
 		buildModelConverter().for( data.modelToView, editing.modelToView )

+ 2 - 4
packages/ckeditor5-basic-styles/src/italicengine.js

@@ -31,10 +31,8 @@ export default class ItalicEngine extends Plugin {
 		const data = editor.data;
 		const data = editor.data;
 		const editing = editor.editing;
 		const editing = editor.editing;
 
 
-		// Allow italic attribute on all inline nodes.
-		editor.model.schema.allow( { name: '$inline', attributes: ITALIC, inside: '$block' } );
-		// Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
-		editor.model.schema.allow( { name: '$inline', attributes: ITALIC, inside: '$clipboardHolder' } );
+		// Allow italic attribute on text nodes.
+		editor.model.schema.extend( '$text', { allowAttributes: ITALIC } );
 
 
 		// Build converter from model to view for data and editing pipelines.
 		// Build converter from model to view for data and editing pipelines.
 		buildModelConverter().for( data.modelToView, editing.modelToView )
 		buildModelConverter().for( data.modelToView, editing.modelToView )

+ 2 - 4
packages/ckeditor5-basic-styles/src/strikethroughengine.js

@@ -32,10 +32,8 @@ export default class StrikethroughEngine extends Plugin {
 		const data = editor.data;
 		const data = editor.data;
 		const editing = editor.editing;
 		const editing = editor.editing;
 
 
-		// Allow strikethrough attribute on all inline nodes.
-		editor.model.schema.allow( { name: '$inline', attributes: STRIKETHROUGH, inside: '$block' } );
-		// Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
-		editor.model.schema.allow( { name: '$inline', attributes: STRIKETHROUGH, inside: '$clipboardHolder' } );
+		// Allow strikethrough attribute on text nodes.
+		editor.model.schema.extend( '$text', { allowAttributes: STRIKETHROUGH } );
 
 
 		// Build converter from model to view for data and editing pipelines.
 		// Build converter from model to view for data and editing pipelines.
 		buildModelConverter().for( data.modelToView, editing.modelToView )
 		buildModelConverter().for( data.modelToView, editing.modelToView )

+ 2 - 4
packages/ckeditor5-basic-styles/src/underlineengine.js

@@ -31,10 +31,8 @@ export default class UnderlineEngine extends Plugin {
 		const data = editor.data;
 		const data = editor.data;
 		const editing = editor.editing;
 		const editing = editor.editing;
 
 
-		// Allow underline attribute on all inline nodes.
-		editor.model.schema.allow( { name: '$inline', attributes: UNDERLINE, inside: '$block' } );
-		// Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
-		editor.model.schema.allow( { name: '$inline', attributes: UNDERLINE, inside: '$clipboardHolder' } );
+		// Allow strikethrough attribute on text nodes.
+		editor.model.schema.extend( '$text', { allowAttributes: UNDERLINE } );
 
 
 		// Build converter from model to view for data and editing pipelines.
 		// Build converter from model to view for data and editing pipelines.
 		buildModelConverter().for( data.modelToView, editing.modelToView )
 		buildModelConverter().for( data.modelToView, editing.modelToView )

+ 18 - 15
packages/ckeditor5-basic-styles/tests/attributecommand.js

@@ -26,20 +26,21 @@ describe( 'AttributeCommand', () => {
 
 
 				command = new AttributeCommand( editor, attrKey );
 				command = new AttributeCommand( editor, attrKey );
 
 
-				model.schema.registerItem( 'p', '$block' );
-				model.schema.registerItem( 'h1', '$block' );
-				model.schema.registerItem( 'img', '$inline' );
-				model.schema.objects.add( 'img' );
+				model.schema.register( 'p', { inheritAllFrom: '$block' } );
+				model.schema.register( 'h1', { inheritAllFrom: '$block' } );
+				model.schema.register( 'img', {
+					allowWhere: '$block',
+					isObject: true
+				} );
 
 
-				// Allow block in "root" (DIV)
-				model.schema.allow( { name: '$block', inside: '$root' } );
+				// TODO the following rules are odd
 
 
 				// Bold text is allowed only in P.
 				// Bold text is allowed only in P.
-				model.schema.allow( { name: '$text', attributes: 'bold', inside: 'p' } );
-				model.schema.allow( { name: 'p', attributes: 'bold', inside: '$root' } );
+				// model.schema.xallow( { name: '$text', attributes: 'bold', inside: 'p' } );
+				// model.schema.xallow( { name: 'p', attributes: 'bold', inside: '$root' } );
 
 
 				// Disallow bold on image.
 				// Disallow bold on image.
-				model.schema.disallow( { name: 'img', attributes: 'bold', inside: '$root' } );
+				// model.schema.xdisallow( { name: 'img', attributes: 'bold', inside: '$root' } );
 			} );
 			} );
 	} );
 	} );
 
 
@@ -68,10 +69,12 @@ describe( 'AttributeCommand', () => {
 
 
 		// See https://github.com/ckeditor/ckeditor5-core/issues/73#issuecomment-311572827.
 		// See https://github.com/ckeditor/ckeditor5-core/issues/73#issuecomment-311572827.
 		it( 'is false when selection contains object with nested editable', () => {
 		it( 'is false when selection contains object with nested editable', () => {
-			model.schema.registerItem( 'caption', '$block' );
-			model.schema.allow( { name: '$inline', inside: 'caption' } );
-			model.schema.allow( { name: 'caption', inside: 'img' } );
-			model.schema.allow( { name: '$text', attributes: 'bold', inside: 'caption' } );
+			model.schema.register( 'caption', { inheritAllFrom: '$block' } );
+			model.schema.extend( '$text', {
+				allowIn: 'caption',
+				allowAttributes: 'bold'
+			} );
+			model.schema.extend( 'caption', { allowIn: 'img' } );
 
 
 			setData( model, '<p>[<img><caption>Some caption inside the image.</caption></img>]</p>' );
 			setData( model, '<p>[<img><caption>Some caption inside the image.</caption></img>]</p>' );
 
 
@@ -90,7 +93,7 @@ describe( 'AttributeCommand', () => {
 		// Method `refresh()` uses `checkAttributeInSelection()` which is fully tested in its own test.
 		// Method `refresh()` uses `checkAttributeInSelection()` which is fully tested in its own test.
 
 
 		beforeEach( () => {
 		beforeEach( () => {
-			model.schema.registerItem( 'x', '$block' );
+			model.schema.register( 'x', { inheritAllFrom: '$block' } );
 			model.schema.disallow( { name: '$text', inside: 'x', attributes: 'link' } );
 			model.schema.disallow( { name: '$text', inside: 'x', attributes: 'link' } );
 		} );
 		} );
 
 
@@ -239,7 +242,7 @@ describe( 'AttributeCommand', () => {
 		} );
 		} );
 
 
 		it( 'should not apply attribute change where it would invalid schema', () => {
 		it( 'should not apply attribute change where it would invalid schema', () => {
-			model.schema.registerItem( 'image', '$block' );
+			model.schema.register( 'image', { inheritAllFrom: '$block' } );
 			setData( model, '<p>ab[c<img></img><$text bold="true">foobar</$text>xy<img></img>]z</p>' );
 			setData( model, '<p>ab[c<img></img><$text bold="true">foobar</$text>xy<img></img>]z</p>' );
 
 
 			expect( command.isEnabled ).to.be.true;
 			expect( command.isEnabled ).to.be.true;

+ 3 - 3
packages/ckeditor5-basic-styles/tests/boldengine.js

@@ -35,9 +35,9 @@ describe( 'BoldEngine', () => {
 	} );
 	} );
 
 
 	it( 'should set proper schema rules', () => {
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.check( { name: '$inline', attributes: 'bold', inside: '$root' } ) ).to.be.false;
-		expect( model.schema.check( { name: '$inline', attributes: 'bold', inside: '$block' } ) ).to.be.true;
-		expect( model.schema.check( { name: '$inline', attributes: 'bold', inside: '$clipboardHolder' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'bold', inside: '$root' } ) ).to.be.false;
+		expect( model.schema.check( { name: '$text', attributes: 'bold', inside: '$block' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'bold', inside: '$clipboardHolder' } ) ).to.be.true;
 	} );
 	} );
 
 
 	describe( 'command', () => {
 	describe( 'command', () => {

+ 3 - 3
packages/ckeditor5-basic-styles/tests/codeengine.js

@@ -35,9 +35,9 @@ describe( 'CodeEngine', () => {
 	} );
 	} );
 
 
 	it( 'should set proper schema rules', () => {
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.check( { name: '$inline', attributes: 'code', inside: '$root' } ) ).to.be.false;
-		expect( model.schema.check( { name: '$inline', attributes: 'code', inside: '$block' } ) ).to.be.true;
-		expect( model.schema.check( { name: '$inline', attributes: 'code', inside: '$clipboardHolder' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'code', inside: '$root' } ) ).to.be.false;
+		expect( model.schema.check( { name: '$text', attributes: 'code', inside: '$block' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'code', inside: '$clipboardHolder' } ) ).to.be.true;
 	} );
 	} );
 
 
 	describe( 'command', () => {
 	describe( 'command', () => {

+ 3 - 3
packages/ckeditor5-basic-styles/tests/italicengine.js

@@ -35,9 +35,9 @@ describe( 'ItalicEngine', () => {
 	} );
 	} );
 
 
 	it( 'should set proper schema rules', () => {
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.check( { name: '$inline', attributes: 'italic', inside: '$root' } ) ).to.be.false;
-		expect( model.schema.check( { name: '$inline', attributes: 'italic', inside: '$block' } ) ).to.be.true;
-		expect( model.schema.check( { name: '$inline', attributes: 'italic', inside: '$clipboardHolder' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'italic', inside: '$root' } ) ).to.be.false;
+		expect( model.schema.check( { name: '$text', attributes: 'italic', inside: '$block' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'italic', inside: '$clipboardHolder' } ) ).to.be.true;
 	} );
 	} );
 
 
 	describe( 'command', () => {
 	describe( 'command', () => {

+ 3 - 3
packages/ckeditor5-basic-styles/tests/strikethroughengine.js

@@ -35,9 +35,9 @@ describe( 'StrikethroughEngine', () => {
 	} );
 	} );
 
 
 	it( 'should set proper schema rules', () => {
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.check( { name: '$inline', attributes: 'strikethrough', inside: '$root' } ) ).to.be.false;
-		expect( model.schema.check( { name: '$inline', attributes: 'strikethrough', inside: '$block' } ) ).to.be.true;
-		expect( model.schema.check( { name: '$inline', attributes: 'strikethrough', inside: '$clipboardHolder' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'strikethrough', inside: '$root' } ) ).to.be.false;
+		expect( model.schema.check( { name: '$text', attributes: 'strikethrough', inside: '$block' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'strikethrough', inside: '$clipboardHolder' } ) ).to.be.true;
 	} );
 	} );
 
 
 	describe( 'command', () => {
 	describe( 'command', () => {

+ 3 - 3
packages/ckeditor5-basic-styles/tests/underlineengine.js

@@ -35,9 +35,9 @@ describe( 'UnderlineEngine', () => {
 	} );
 	} );
 
 
 	it( 'should set proper schema rules', () => {
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.check( { name: '$inline', attributes: 'underline', inside: '$root' } ) ).to.be.false;
-		expect( model.schema.check( { name: '$inline', attributes: 'underline', inside: '$block' } ) ).to.be.true;
-		expect( model.schema.check( { name: '$inline', attributes: 'underline', inside: '$clipboardHolder' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'underline', inside: '$root' } ) ).to.be.false;
+		expect( model.schema.check( { name: '$text', attributes: 'underline', inside: '$block' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'underline', inside: '$clipboardHolder' } ) ).to.be.true;
 	} );
 	} );
 
 
 	describe( 'command', () => {
 	describe( 'command', () => {