Procházet zdrojové kódy

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

Piotrek Koszuliński před 8 roky
rodič
revize
76cac35591

+ 2 - 3
packages/ckeditor5-image/src/imagecaption/imagecaptionengine.js

@@ -59,10 +59,9 @@ export default class ImageCaptionEngine extends Plugin {
 		this._createCaption = captionElementCreator( viewDocument, t( 'Enter image caption' ) );
 
 		// Schema configuration.
-		schema.register( 'caption', { inheritAllFrom: '$block' } );
-		schema.extend( '$text', { allowIn: 'caption' } );
-		schema.extend( 'caption', {
+		schema.register( 'caption', {
 			allowIn: 'image',
+			allowContentOf: '$block',
 			isLimit: true
 		} );
 

+ 2 - 2
packages/ckeditor5-image/tests/image/converters.js

@@ -257,7 +257,7 @@ describe( 'Image converters', () => {
 			} );
 
 			it( 'should not convert img element if allowed context is "above" limiting element #1', () => {
-				schema.extend( 'limit', { isLimit: true } );
+				schema.register( 'limit', { isLimit: true } );
 
 				const result = dispatcher.convert( viewImg, { context: [ '$root', 'limit', 'div', 'paragraph' ] } );
 
@@ -267,7 +267,7 @@ describe( 'Image converters', () => {
 			} );
 
 			it( 'should not convert img element if allowed context is "above" limiting element #2', () => {
-				schema.extend( 'limit', { isLimit: true } );
+				schema.register( 'limit', { isLimit: true } );
 
 				const result = dispatcher.convert( viewImg, { context: [ '$root', modelLimit, modelDiv, modelParagraph ] } );
 

+ 8 - 1
packages/ckeditor5-image/tests/image/imageengine.js

@@ -179,7 +179,14 @@ describe( 'ImageEngine', () => {
 				const editing = editor.editing;
 
 				model.schema.register( 'div', { inheritAllFrom: '$block' } );
-				model.schema.disallow( { name: 'image', inside: '$root', attributes: 'src' } );
+				model.schema.on( 'checkChild', ( evt, args ) => {
+					const rule = model.schema.getRule( args[ 1 ] );
+
+					if ( args[ 0 ].matchEnd( '$root' ) && rule.name == 'image' ) {
+						evt.stop();
+						evt.return = false;
+					}
+				}, { priority: 'high' } );
 
 				buildModelConverter().for( data.modelToView, editing.modelToView ).fromElement( 'div' ).toElement( 'div' );
 				buildViewConverter().for( data.viewToModel ).fromElement( 'div' ).toElement( 'div' );

+ 3 - 0
packages/ckeditor5-image/tests/imagecaption/imagecaptionengine.js

@@ -62,6 +62,9 @@ describe( 'ImageCaptionEngine', () => {
 		expect( model.schema.isLimit( 'caption' ) ).to.be.true;
 
 		expect( model.schema.checkChild( [ '$root', 'image', 'caption' ], 'caption' ) ).to.be.false;
+
+		model.schema.extend( '$block', { allowAttributes: 'aligmnent' } );
+		expect( model.schema.checkAttribute( [ '$root', 'image', 'caption' ], 'alignment' ) ).to.be.false;
 	} );
 
 	describe( 'data pipeline', () => {

+ 7 - 1
packages/ckeditor5-image/tests/imagestyle/imagestyleengine.js

@@ -122,7 +122,13 @@ describe( 'ImageStyleEngine', () => {
 		} );
 
 		it( 'should not convert from view to model if schema prevents it', () => {
-			model.schema.disallow( { name: 'image', attributes: 'imageStyle' } );
+			model.schema.on( 'checkAttribute', ( evt, args ) => {
+				if ( args[ 0 ].matchEnd( 'image' ) && args[ 1 ] == 'imageStyle' ) {
+					evt.stop();
+					evt.return = false;
+				}
+			} );
+
 			editor.setData( '<figure class="image side-class"><img src="foo.png" /></figure>' );
 
 			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<image src="foo.png"></image>' );