Преглед на файлове

Merge branch t/ckeditor5-engine/532

Internal: Aligned Schema API use to the new Schema API.
Piotrek Koszuliński преди 8 години
родител
ревизия
1544a13ca6

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

@@ -31,10 +31,8 @@ export default class BoldEngine extends Plugin {
 		const data = editor.data;
 		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.
 		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 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.
 		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 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.
 		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 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.
 		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 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.
 		buildModelConverter().for( data.modelToView, editing.modelToView )

+ 28 - 21
packages/ckeditor5-basic-styles/tests/attributecommand.js

@@ -26,20 +26,23 @@ describe( 'AttributeCommand', () => {
 
 				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' );
-
-				// Allow block in "root" (DIV)
-				model.schema.allow( { name: '$block', inside: '$root' } );
-
-				// 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' } );
-
-				// Disallow bold on image.
-				model.schema.disallow( { name: 'img', attributes: 'bold', inside: '$root' } );
+				model.schema.register( 'p', { inheritAllFrom: '$block' } );
+				model.schema.register( 'h1', { inheritAllFrom: '$block' } );
+				model.schema.register( 'img', {
+					allowWhere: [ '$block', '$text' ],
+					isObject: true
+				} );
+
+				model.schema.on( 'checkAttribute', ( evt, args ) => {
+					const ctx = args[ 0 ];
+					const attributeName = args[ 1 ];
+
+					// Allow 'bold' on p>$text.
+					if ( ctx.endsWith( 'p $text' ) && attributeName == 'bold' ) {
+						evt.stop();
+						evt.return = true;
+					}
+				}, { priority: 'high' } );
 			} );
 	} );
 
@@ -68,10 +71,15 @@ describe( 'AttributeCommand', () => {
 
 		// See https://github.com/ckeditor/ckeditor5-core/issues/73#issuecomment-311572827.
 		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', {
+				allowContentOf: '$block',
+				allowIn: 'img',
+				isLimit: true
+			} );
+			model.schema.extend( '$text', {
+				allowIn: 'caption',
+				allowAttributes: 'bold'
+			} );
 
 			setData( model, '<p>[<img><caption>Some caption inside the image.</caption></img>]</p>' );
 
@@ -90,8 +98,7 @@ describe( 'AttributeCommand', () => {
 		// Method `refresh()` uses `checkAttributeInSelection()` which is fully tested in its own test.
 
 		beforeEach( () => {
-			model.schema.registerItem( 'x', '$block' );
-			model.schema.disallow( { name: '$text', inside: 'x', attributes: 'link' } );
+			model.schema.register( 'x', { inheritAllFrom: '$block' } );
 		} );
 
 		describe( 'when selection is collapsed', () => {
@@ -239,7 +246,7 @@ describe( 'AttributeCommand', () => {
 		} );
 
 		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>' );
 
 			expect( command.isEnabled ).to.be.true;

+ 6 - 5
packages/ckeditor5-basic-styles/tests/bold.js

@@ -12,6 +12,8 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
 testUtils.createSinonSandbox();
 
 describe( 'Bold', () => {
@@ -23,7 +25,7 @@ describe( 'Bold', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ Bold ]
+				plugins: [ Paragraph, Bold ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -65,14 +67,13 @@ describe( 'Bold', () => {
 		const command = editor.commands.get( 'bold' );
 
 		expect( boldView.isOn ).to.be.false;
-
-		expect( boldView.isEnabled ).to.be.false;
+		expect( boldView.isEnabled ).to.be.true;
 
 		command.value = true;
 		expect( boldView.isOn ).to.be.true;
 
-		command.isEnabled = true;
-		expect( boldView.isEnabled ).to.be.true;
+		command.isEnabled = false;
+		expect( boldView.isEnabled ).to.be.false;
 	} );
 
 	it( 'should set keystroke in the model', () => {

+ 5 - 8
packages/ckeditor5-basic-styles/tests/boldengine.js

@@ -35,9 +35,8 @@ describe( 'BoldEngine', () => {
 	} );
 
 	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.checkAttribute( [ '$root', '$block', '$text' ], 'bold' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'bold' ) ).to.be.true;
 	} );
 
 	describe( 'command', () => {
@@ -78,14 +77,12 @@ describe( 'BoldEngine', () => {
 		} );
 
 		it( 'should be integrated with autoparagraphing', () => {
-			// Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
-			// https://github.com/ckeditor/ckeditor5-paragraph/issues/10
-
 			editor.setData( '<strong>foo</strong>bar' );
 
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text bold="true">foo</$text>bar</paragraph>' );
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><strong>foo</strong>bar</p>' );
 		} );
 	} );
 

+ 6 - 5
packages/ckeditor5-basic-styles/tests/code.js

@@ -11,6 +11,8 @@ import CodeEngine from '../src/codeengine';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
 testUtils.createSinonSandbox();
 
 describe( 'Code', () => {
@@ -22,7 +24,7 @@ describe( 'Code', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ Code ]
+				plugins: [ Paragraph, Code ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -63,13 +65,12 @@ describe( 'Code', () => {
 		const command = editor.commands.get( 'code' );
 
 		expect( codeView.isOn ).to.be.false;
-
-		expect( codeView.isEnabled ).to.be.false;
+		expect( codeView.isEnabled ).to.be.true;
 
 		command.value = true;
 		expect( codeView.isOn ).to.be.true;
 
-		command.isEnabled = true;
-		expect( codeView.isEnabled ).to.be.true;
+		command.isEnabled = false;
+		expect( codeView.isEnabled ).to.be.false;
 	} );
 } );

+ 5 - 8
packages/ckeditor5-basic-styles/tests/codeengine.js

@@ -35,9 +35,8 @@ describe( 'CodeEngine', () => {
 	} );
 
 	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.checkAttribute( [ '$root', '$block', '$text' ], 'code' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'code' ) ).to.be.true;
 	} );
 
 	describe( 'command', () => {
@@ -69,14 +68,12 @@ describe( 'CodeEngine', () => {
 		} );
 
 		it( 'should be integrated with autoparagraphing', () => {
-			// Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
-			// https://github.com/ckeditor/ckeditor5-paragraph/issues/10
-
 			editor.setData( '<code>foo</code>bar' );
 
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text code="true">foo</$text>bar</paragraph>' );
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><code>foo</code>bar</p>' );
 		} );
 	} );
 

+ 6 - 5
packages/ckeditor5-basic-styles/tests/italic.js

@@ -12,6 +12,8 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
 testUtils.createSinonSandbox();
 
 describe( 'Italic', () => {
@@ -23,7 +25,7 @@ describe( 'Italic', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ Italic ]
+				plugins: [ Paragraph, Italic ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -65,14 +67,13 @@ describe( 'Italic', () => {
 		const command = editor.commands.get( 'italic' );
 
 		expect( italicView.isOn ).to.be.false;
-
-		expect( italicView.isEnabled ).to.be.false;
+		expect( italicView.isEnabled ).to.be.true;
 
 		command.value = true;
 		expect( italicView.isOn ).to.be.true;
 
-		command.isEnabled = true;
-		expect( italicView.isEnabled ).to.be.true;
+		command.isEnabled = false;
+		expect( italicView.isEnabled ).to.be.false;
 	} );
 
 	it( 'should set keystroke in the model', () => {

+ 6 - 9
packages/ckeditor5-basic-styles/tests/italicengine.js

@@ -35,9 +35,8 @@ describe( 'ItalicEngine', () => {
 	} );
 
 	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.checkAttribute( [ '$root', '$block', '$text' ], 'italic' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'italic' ) ).to.be.true;
 	} );
 
 	describe( 'command', () => {
@@ -78,14 +77,12 @@ describe( 'ItalicEngine', () => {
 		} );
 
 		it( 'should be integrated with autoparagraphing', () => {
-			// Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
-			// https://github.com/ckeditor/ckeditor5-paragraph/issues/10
+			editor.setData( '<i>foo</i>bar' );
 
-			editor.setData( '<em>foo</em>bar' );
-
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><i>foo</i>bar</p>' );
 		} );
 	} );
 

+ 6 - 5
packages/ckeditor5-basic-styles/tests/strikethrough.js

@@ -12,6 +12,8 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
 testUtils.createSinonSandbox();
 
 describe( 'Strikethrough', () => {
@@ -23,7 +25,7 @@ describe( 'Strikethrough', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ Strikethrough ]
+				plugins: [ Paragraph, Strikethrough ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -65,14 +67,13 @@ describe( 'Strikethrough', () => {
 		const command = editor.commands.get( 'strikethrough' );
 
 		expect( strikeView.isOn ).to.be.false;
-
-		expect( strikeView.isEnabled ).to.be.false;
+		expect( strikeView.isEnabled ).to.be.true;
 
 		command.value = true;
 		expect( strikeView.isOn ).to.be.true;
 
-		command.isEnabled = true;
-		expect( strikeView.isEnabled ).to.be.true;
+		command.isEnabled = false;
+		expect( strikeView.isEnabled ).to.be.false;
 	} );
 
 	it( 'should set keystroke in the model', () => {

+ 5 - 8
packages/ckeditor5-basic-styles/tests/strikethroughengine.js

@@ -35,9 +35,8 @@ describe( 'StrikethroughEngine', () => {
 	} );
 
 	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.checkAttribute( [ '$root', '$block', '$text' ], 'strikethrough' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'strikethrough' ) ).to.be.true;
 	} );
 
 	describe( 'command', () => {
@@ -86,14 +85,12 @@ describe( 'StrikethroughEngine', () => {
 		} );
 
 		it( 'should be integrated with autoparagraphing', () => {
-			// Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
-			// https://github.com/ckeditor/ckeditor5-paragraph/issues/10
-
 			editor.setData( '<s>foo</s>bar' );
 
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
 		} );
 	} );
 

+ 6 - 5
packages/ckeditor5-basic-styles/tests/underline.js

@@ -12,6 +12,8 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
 testUtils.createSinonSandbox();
 
 describe( 'Underline', () => {
@@ -23,7 +25,7 @@ describe( 'Underline', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ Underline ]
+				plugins: [ Paragraph, Underline ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -65,14 +67,13 @@ describe( 'Underline', () => {
 		const command = editor.commands.get( 'underline' );
 
 		expect( underlineView.isOn ).to.be.false;
-
-		expect( underlineView.isEnabled ).to.be.false;
+		expect( underlineView.isEnabled ).to.be.true;
 
 		command.value = true;
 		expect( underlineView.isOn ).to.be.true;
 
-		command.isEnabled = true;
-		expect( underlineView.isEnabled ).to.be.true;
+		command.isEnabled = false;
+		expect( underlineView.isEnabled ).to.be.false;
 	} );
 
 	it( 'should set keystroke in the model', () => {

+ 5 - 8
packages/ckeditor5-basic-styles/tests/underlineengine.js

@@ -35,9 +35,8 @@ describe( 'UnderlineEngine', () => {
 	} );
 
 	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.checkAttribute( [ '$root', '$block', '$text' ], 'underline' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'underline' ) ).to.be.true;
 	} );
 
 	describe( 'command', () => {
@@ -69,14 +68,12 @@ describe( 'UnderlineEngine', () => {
 		} );
 
 		it( 'should be integrated with autoparagraphing', () => {
-			// Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
-			// https://github.com/ckeditor/ckeditor5-paragraph/issues/10
-
 			editor.setData( '<u>foo</u>bar' );
 
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text underline="true">foo</$text>bar</paragraph>' );
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><u>foo</u>bar</p>' );
 		} );
 	} );