Bladeren bron

Merge branch t/ckeditor5-engine/532

Internal: Aligned Schema API use to the new Schema API.
Piotrek Koszuliński 8 jaren geleden
bovenliggende
commit
d95ab0fa60

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

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

+ 2 - 2
packages/ckeditor5-link/tests/findlinkrange.js

@@ -16,8 +16,8 @@ describe( 'findLinkRange', () => {
 		model = new Model();
 		document = model.document;
 		root = document.createRoot();
-		model.schema.allow( { name: '$text', inside: '$root' } );
-		model.schema.registerItem( 'p', '$block' );
+		model.schema.extend( '$text', { allowIn: '$root' } );
+		model.schema.register( 'p', { inheritAllFrom: '$block' } );
 	} );
 
 	it( 'should find link range searching from the center of the link #1', () => {

+ 1 - 1
packages/ckeditor5-link/tests/link.js

@@ -594,7 +594,7 @@ describe( 'Link', () => {
 
 			beforeEach( () => {
 				observer = editor.editing.view.getObserver( ClickObserver );
-				editor.model.schema.allow( { name: '$text', inside: '$root' } );
+				editor.model.schema.extend( '$text', { allowIn: '$root' } );
 
 				spy = testUtils.sinon.stub( linkFeature, '_showPanel' ).returns( {} );
 			} );

+ 21 - 11
packages/ckeditor5-link/tests/linkcommand.js

@@ -17,13 +17,12 @@ describe( 'LinkCommand', () => {
 				model = editor.model;
 				command = new LinkCommand( editor );
 
-				// Allow text in $root.
-				model.schema.allow( { name: '$text', inside: '$root' } );
+				model.schema.extend( '$text', {
+					allowIn: '$root',
+					allowAttributes: 'linkHref'
+				} );
 
-				// Allow text with `linkHref` attribute in paragraph.
-				model.schema.registerItem( 'p', '$block' );
-				model.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
-				model.schema.allow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
+				model.schema.register( 'p', { inheritAllFrom: '$block' } );
 			} );
 	} );
 
@@ -36,8 +35,14 @@ describe( 'LinkCommand', () => {
 		// refresh() uses `isAttributeAllowedInSelection` helper which is fully tested in his own test.
 
 		beforeEach( () => {
-			model.schema.registerItem( 'x', '$block' );
-			model.schema.disallow( { name: '$text', inside: 'x', attributes: 'linkHref' } );
+			model.schema.register( 'x', { inheritAllFrom: '$block' } );
+
+			model.schema.on( 'checkAttribute', ( evt, args ) => {
+				if ( args[ 0 ].endsWith( 'x $text' ) && args[ 1 ] == 'linkHref' ) {
+					evt.stop();
+					evt.return = false;
+				}
+			}, { priority: 'high' } );
 		} );
 
 		describe( 'when selection is collapsed', () => {
@@ -189,8 +194,7 @@ describe( 'LinkCommand', () => {
 			} );
 
 			it( 'should set `linkHref` attribute only to allowed elements and omit disallowed', () => {
-				// Disallow text in img.
-				model.schema.registerItem( 'img', '$inline' );
+				model.schema.register( 'img', { allowWhere: '$text' } );
 
 				setData( model, '<p>f[oo<img></img>ba]r</p>' );
 
@@ -234,7 +238,13 @@ describe( 'LinkCommand', () => {
 			} );
 
 			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 ].endsWith( 'p $text' ) && args[ 1 ] == 'linkHref' ) {
+						evt.stop();
+						evt.return = false;
+					}
+				}, { priority: 'high' } );
+
 				setData( model, '<p>foo[]bar</p>' );
 
 				command.execute( 'url' );

+ 8 - 9
packages/ckeditor5-link/tests/linkengine.js

@@ -34,9 +34,10 @@ describe( 'LinkEngine', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$root' } ) ).to.be.false;
-		expect( model.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$block' } ) ).to.be.true;
-		expect( model.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$clipboardHolder' } ) ).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( [ '$block' ], 'linkHref' ) ).to.be.false;
 	} );
 
 	describe( 'command', () => {
@@ -64,14 +65,12 @@ describe( 'LinkEngine', () => {
 		} );
 
 		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' );
 
-			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
@@ -108,7 +107,7 @@ describe( 'LinkEngine', () => {
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/121
 		it( 'should should set priority for `linkHref` higher than all other attribute elements', () => {
-			model.schema.allow( { name: '$inline', attributes: [ 'foo' ], inside: '$block' } );
+			model.schema.extend( '$text', { allowAttributes: 'foo' } );
 
 			buildModelConverter().for( editor.data.modelToView )
 				.fromAttribute( 'foo' )

+ 5 - 5
packages/ckeditor5-link/tests/unlinkcommand.js

@@ -21,12 +21,12 @@ describe( 'UnlinkCommand', () => {
 				document = model.document;
 				command = new UnlinkCommand( editor );
 
-				// Allow text in $root.
-				model.schema.allow( { name: '$text', inside: '$root' } );
+				model.schema.extend( '$text', {
+					allowIn: '$root',
+					allowAttributes: 'linkHref'
+				} );
 
-				// Allow text with `linkHref` attribute in paragraph.
-				model.schema.registerItem( 'p', '$block' );
-				model.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
+				model.schema.register( 'p', { inheritAllFrom: '$block' } );
 			} );
 	} );