ソースを参照

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

Piotrek Koszuliński 8 年 前
コミット
a724da7741

+ 4 - 4
packages/ckeditor5-upload/src/imageuploadengine.js

@@ -36,10 +36,10 @@ export default class ImageUploadEngine extends Plugin {
 		const schema = editor.model.schema;
 		const fileRepository = editor.plugins.get( FileRepository );
 
-		// Setup schema to allow uploadId for images.
-		schema.allow( { name: 'image', attributes: [ 'uploadId' ], inside: '$root' } );
-		schema.allow( { name: 'image', attributes: [ 'uploadStatus' ], inside: '$root' } );
-		schema.requireAttributes( 'image', [ 'uploadId' ] );
+		// Setup schema to allow uploadId and uploadStatus for images.
+		schema.extend( 'image', {
+			allowAttributes: [ 'uploadId', 'uploadStatus' ]
+		} );
 
 		// Register imageUpload command.
 		editor.commands.add( 'imageUpload', new ImageUploadCommand( editor ) );

+ 8 - 6
packages/ckeditor5-upload/tests/imageuploadcommand.js

@@ -48,8 +48,7 @@ describe( 'ImageUploadCommand', () => {
 				command = new ImageUploadCommand( editor );
 
 				const schema = model.schema;
-				schema.allow( { name: 'image', attributes: [ 'uploadId' ], inside: '$root' } );
-				schema.requireAttributes( 'image', [ 'uploadId' ] );
+				schema.extend( 'image', { allowAttributes: 'uploadId' } );
 			} );
 	} );
 
@@ -98,10 +97,13 @@ describe( 'ImageUploadCommand', () => {
 
 		it( 'should not insert image nor crash when image could not be inserted', () => {
 			const file = createNativeFileMock();
-			model.schema.registerItem( 'other' );
-			model.schema.allow( { name: '$text', inside: 'other' } );
-			model.schema.allow( { name: 'other', inside: '$root' } );
-			model.schema.limits.add( 'other' );
+
+			model.schema.register( 'other', {
+				allowIn: '$root',
+				isLimit: true
+			} );
+			model.schema.extend( '$text', { allowIn: 'other' } );
+
 			buildModelConverter().for( editor.editing.modelToView )
 				.fromElement( 'other' )
 				.toElement( 'p' );

+ 10 - 8
packages/ckeditor5-upload/tests/utils.js

@@ -40,15 +40,17 @@ describe( 'upload utils', () => {
 
 			doc.createRoot();
 
-			model.schema.registerItem( 'paragraph', '$block' );
-			model.schema.registerItem( 'image' );
-			model.schema.registerItem( 'span' );
+			model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
+			model.schema.register( 'image' );
+			model.schema.register( 'span' );
 
-			model.schema.allow( { name: 'image', inside: '$root' } );
-			model.schema.objects.add( 'image' );
+			model.schema.extend( 'image', {
+				allowIn: '$root',
+				isObject: true
+			} );
 
-			model.schema.allow( { name: 'span', inside: 'paragraph' } );
-			model.schema.allow( { name: '$text', inside: 'span' } );
+			model.schema.extend( 'span', { allowIn: 'paragraph' } );
+			model.schema.extend( '$text', { allowIn: 'span' } );
 		} );
 
 		it( 'returns position after selected element', () => {
@@ -101,7 +103,7 @@ describe( 'upload utils', () => {
 		} );
 
 		it( 'returns selection focus if not in a block', () => {
-			model.schema.allow( { name: '$text', inside: '$root' } );
+			model.schema.extend( '$text', { allowIn: '$root' } );
 			setData( model, 'foo[]bar' );
 
 			const pos = findOptimalInsertionPosition( doc.selection );