瀏覽代碼

Merge branch t/ckeditor5-engine/532

Internal: Aligned Schema API use to the new Schema API.
Piotrek Koszuliński 8 年之前
父節點
當前提交
3dbfbfecd0

+ 1 - 8
packages/ckeditor5-alignment/src/alignmentcommand.js

@@ -98,14 +98,7 @@ export default class AlignmentCommand extends Command {
 	 * @private
 	 */
 	_canBeAligned( block ) {
-		const schema = this.editor.model.schema;
-
-		// Check if adding alignment attribute to selected block is allowed.
-		return schema.check( {
-			name: block.name,
-			// Apparently I must pass current attributes as otherwise adding alignment on listItem will fail.
-			attributes: [ ...block.getAttributeKeys(), 'alignment' ]
-		} );
+		return this.editor.model.schema.checkAttribute( block, 'alignment' );
 	}
 
 	/**

+ 1 - 13
packages/ckeditor5-alignment/src/alignmentediting.js

@@ -55,7 +55,7 @@ export default class AlignmentEditing extends Plugin {
 		const enabledStyles = editor.config.get( 'alignment.styles' );
 
 		// Allow alignment attribute on all blocks.
-		schema.allow( { name: '$block', attributes: 'alignment' } );
+		schema.extend( '$block', { allowAttributes: 'alignment' } );
 
 		data.modelToView.on( 'attribute:alignment', convertStyle() );
 		editing.modelToView.on( 'attribute:alignment', convertStyle() );
@@ -82,18 +82,6 @@ export default class AlignmentEditing extends Plugin {
 				editor.commands.add( commandNameFromStyle( style ), new AlignmentCommand( editor, style, isDefault( style ) ) );
 			} );
 	}
-
-	/**
-	 * @inheritDoc
-	 */
-	afterInit() {
-		const schema = this.editor.model.schema;
-
-		// Disallow alignment on caption elements.
-		if ( schema.hasItem( 'caption' ) ) {
-			schema.disallow( { name: 'caption', attributes: 'alignment' } );
-		}
-	}
 }
 
 /**

+ 2 - 3
packages/ckeditor5-alignment/tests/alignmentcommand.js

@@ -24,9 +24,8 @@ describe( 'AlignmentCommand', () => {
 				editor.commands.add( 'alignCenter', command );
 				editor.commands.add( 'alignLeft', defaultAlignmentCommand );
 
-				model.schema.registerItem( 'paragraph', '$block' );
-
-				model.schema.allow( { name: '$block', inside: '$root', attributes: 'alignment' } );
+				model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
+				model.schema.extend( '$block', { allowAttributes: 'alignment' } );
 			} );
 	} );
 

+ 7 - 5
packages/ckeditor5-alignment/tests/alignmentediting.js

@@ -40,7 +40,7 @@ describe( 'AlignmentEditing', () => {
 	} );
 
 	it( 'allows for alignment in $blocks', () => {
-		expect( model.schema.check( { name: '$block', inside: '$root', attributes: 'alignment' } ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$root', '$block' ], 'alignment' ) ).to.be.true;
 	} );
 
 	describe( 'integration', () => {
@@ -56,19 +56,21 @@ describe( 'AlignmentEditing', () => {
 		} );
 
 		it( 'is allowed on paragraph', () => {
-			expect( model.schema.check( { name: 'paragraph', attributes: 'alignment' } ) ).to.be.true;
+			expect( model.schema.checkAttribute( [ '$root', 'paragraph' ], 'alignment' ) ).to.be.true;
 		} );
 
 		it( 'is allowed on listItem', () => {
-			expect( model.schema.check( { name: 'listItem', attributes: [ 'type', 'indent', 'alignment' ] } ) ).to.be.true;
+			expect( model.schema.checkAttribute( [ '$root', 'listItem' ], 'type' ) ).to.be.true;
+			expect( model.schema.checkAttribute( [ '$root', 'listItem' ], 'indent' ) ).to.be.true;
+			expect( model.schema.checkAttribute( [ '$root', 'listItem' ], 'alignment' ) ).to.be.true;
 		} );
 
 		it( 'is allowed on heading', () => {
-			expect( model.schema.check( { name: 'heading1', attributes: 'alignment' } ) ).to.be.true;
+			expect( model.schema.checkAttribute( [ '$root', 'heading1' ], 'alignment' ) ).to.be.true;
 		} );
 
 		it( 'is disallowed on caption', () => {
-			expect( model.schema.check( { name: 'caption', attributes: 'alignment' } ) ).to.be.false;
+			expect( model.schema.checkAttribute( [ '$root', 'image', 'caption' ], 'alignment' ) ).to.be.false;
 		} );
 	} );
 

+ 1 - 1
packages/ckeditor5-alignment/tests/alignmentui.js

@@ -12,7 +12,7 @@ import alignLeftIcon from '../theme/icons/align-left.svg';
 
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 
-describe( 'Alignment', () => {
+describe( 'Alignment UI', () => {
 	let editor, command, element, button;
 
 	beforeEach( () => {

+ 1 - 1
packages/ckeditor5-alignment/tests/integration.js

@@ -18,7 +18,7 @@ import Delete from '@ckeditor/ckeditor5-typing/src/delete';
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
-describe( 'Alignment', () => {
+describe( 'Alignment integration', () => {
 	let editor, model, element;
 
 	beforeEach( () => {