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

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

Piotrek Koszuliński 8 лет назад
Родитель
Сommit
2b63b6b976

+ 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.allow( '$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( {} );
 			} );

+ 10 - 10
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,10 @@ 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' } );
+
+			// TODO callback
+			// model.schema.xdisallow( { name: '$text', inside: 'x', attributes: 'linkHref' } );
 		} );
 
 		describe( 'when selection is collapsed', () => {
@@ -189,8 +190,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>' );
 

+ 4 - 4
packages/ckeditor5-link/tests/linkengine.js

@@ -34,9 +34,9 @@ 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.check( { name: '$text', attributes: 'linkHref', inside: '$root' } ) ).to.be.false;
+		expect( model.schema.check( { name: '$text', attributes: 'linkHref', inside: '$block' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', attributes: 'linkHref', inside: '$clipboardHolder' } ) ).to.be.true;
 	} );
 
 	describe( 'command', () => {
@@ -108,7 +108,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.extned( '$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' } );
 			} );
 	} );