Ver Fonte

Third batch of changes aligning schema use to the new API.

Piotrek Koszuliński há 8 anos atrás
pai
commit
22b688b5a5

+ 1 - 1
packages/ckeditor5-link/src/linkengine.js

@@ -31,7 +31,7 @@ export default class LinkEngine extends Plugin {
 		const editing = editor.editing;
 		const editing = editor.editing;
 
 
 		// Allow link attribute on all inline nodes.
 		// Allow link attribute on all inline nodes.
-		editor.model.schema.allow( '$text', { allowAttributes: 'linkHref' } );
+		editor.model.schema.extend( '$text', { allowAttributes: 'linkHref' } );
 
 
 		// 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 )

+ 13 - 3
packages/ckeditor5-link/tests/linkcommand.js

@@ -37,8 +37,12 @@ describe( 'LinkCommand', () => {
 		beforeEach( () => {
 		beforeEach( () => {
 			model.schema.register( 'x', { inheritAllFrom: '$block' } );
 			model.schema.register( 'x', { inheritAllFrom: '$block' } );
 
 
-			// TODO callback
-			// model.schema.xdisallow( { name: '$text', inside: 'x', attributes: 'linkHref' } );
+			model.schema.on( 'checkAttribute', ( evt, args ) => {
+				if ( args[ 0 ].matchEnd( 'x $text' ) && args[ 1 ] == 'linkHref' ) {
+					evt.stop();
+					evt.return = false;
+				}
+			}, { priority: 'high' } );
 		} );
 		} );
 
 
 		describe( 'when selection is collapsed', () => {
 		describe( 'when selection is collapsed', () => {
@@ -234,7 +238,13 @@ describe( 'LinkCommand', () => {
 			} );
 			} );
 
 
 			it( 'should not insert text with `linkHref` attribute when is not allowed in parent', () => {
 			it( 'should not insert text with `linkHref` attribute when is not allowed in parent', () => {
-				model.schema.disallow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
+				model.schema.on( 'checkAttribute', ( evt, args ) => {
+					if ( args[ 0 ].matchEnd( 'p $text' ) && args[ 1 ] == 'linkHref' ) {
+						evt.stop();
+						evt.return = false;
+					}
+				}, { priority: 'high' } );
+
 				setData( model, '<p>foo[]bar</p>' );
 				setData( model, '<p>foo[]bar</p>' );
 
 
 				command.execute( 'url' );
 				command.execute( 'url' );

+ 6 - 7
packages/ckeditor5-link/tests/linkengine.js

@@ -34,9 +34,10 @@ describe( 'LinkEngine', () => {
 	} );
 	} );
 
 
 	it( 'should set proper schema rules', () => {
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.checkAttribute( [ '$root', '$text' ], 'linkHref' ) ).to.be.false;
 		expect( model.schema.checkAttribute( [ '$block', '$text' ], 'linkHref' ) ).to.be.true;
 		expect( model.schema.checkAttribute( [ '$block', '$text' ], 'linkHref' ) ).to.be.true;
 		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'linkHref' ) ).to.be.true;
 		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'linkHref' ) ).to.be.true;
+
+		expect( model.schema.checkAttribute( [ '$block' ], 'linkHref' ) ).to.be.false;
 	} );
 	} );
 
 
 	describe( 'command', () => {
 	describe( 'command', () => {
@@ -64,14 +65,12 @@ describe( 'LinkEngine', () => {
 		} );
 		} );
 
 
 		it( 'should be integrated with autoparagraphing', () => {
 		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( '<a href="url">foo</a>bar' );
 			editor.setData( '<a href="url">foo</a>bar' );
 
 
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
 
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><a href="url">foo</a>bar</p>' );
 		} );
 		} );
 
 
 		// https://github.com/ckeditor/ckeditor5/issues/500
 		// https://github.com/ckeditor/ckeditor5/issues/500
@@ -108,7 +107,7 @@ describe( 'LinkEngine', () => {
 
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/121
 		// https://github.com/ckeditor/ckeditor5-link/issues/121
 		it( 'should should set priority for `linkHref` higher than all other attribute elements', () => {
 		it( 'should should set priority for `linkHref` higher than all other attribute elements', () => {
-			model.schema.extned( '$text', { allowAttributes: 'foo' } );
+			model.schema.extend( '$text', { allowAttributes: 'foo' } );
 
 
 			buildModelConverter().for( editor.data.modelToView )
 			buildModelConverter().for( editor.data.modelToView )
 				.fromAttribute( 'foo' )
 				.fromAttribute( 'foo' )