Parcourir la source

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

Piotrek Koszuliński il y a 8 ans
Parent
commit
8cccd8276a

+ 4 - 9
packages/ckeditor5-list/src/listengine.js

@@ -50,18 +50,13 @@ export default class ListEngine extends Plugin {
 		const editor = this.editor;
 
 		// Schema.
-		// Note: in case `$block` will be ever allowed in `listItem`, keep in mind that this feature
+		// Note: in case `$block` will ever be allowed in `listItem`, keep in mind that this feature
 		// uses `Selection#getSelectedBlocks()` without any additional processing to obtain all selected list items.
 		// If there are blocks allowed inside list item, algorithms using `getSelectedBlocks()` will have to be modified.
-		const schema = editor.model.schema;
-		schema.registerItem( 'listItem', '$block' );
-		schema.allow( {
-			name: 'listItem',
-			inside: '$root',
-			coinside: '$root',
-			attributes: [ 'type', 'indent' ]
+		editor.model.schema.register( 'listItem', {
+			inheritAllFrom: '$block',
+			allowAttributes: [ 'type', 'indent' ]
 		} );
-		schema.requireAttributes( 'listItem', [ 'type', 'indent' ] );
 
 		// Converters.
 		const data = editor.data;

+ 6 - 7
packages/ckeditor5-list/tests/indentcommand.js

@@ -21,12 +21,11 @@ describe( 'IndentCommand', () => {
 		doc = model.document;
 		root = doc.createRoot();
 
-		model.schema.registerItem( 'listItem', '$block' );
-		model.schema.registerItem( 'paragraph', '$block' );
-
-		model.schema.allow( { name: '$block', inside: '$root' } );
-		model.schema.allow( { name: 'listItem', attributes: [ 'type', 'indent' ], inside: '$root' } );
-		model.schema.allow( { name: 'paragraph', inside: '$root' } );
+		model.schema.register( 'listItem', {
+			inheritAllFrom: '$block',
+			allowAttributes: [ 'type', 'indent' ]
+		} );
+		model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
 
 		setData(
 			model,
@@ -117,7 +116,7 @@ describe( 'IndentCommand', () => {
 			// Edge case but may happen that some other blocks will also use the indent attribute
 			// and before we fixed it the command was enabled in such a case.
 			it( 'should be false if selection starts in a paragraph with indent attribute', () => {
-				model.schema.allow( { name: 'paragraph', attributes: [ 'indent' ], inside: '$root' } );
+				model.schema.extend( 'paragraph', { allowAttributes: 'indent' } );
 
 				setData( model, '<listItem indent="0">a</listItem><paragraph indent="0">b[]</paragraph>' );
 

+ 17 - 12
packages/ckeditor5-list/tests/listcommand.js

@@ -23,14 +23,19 @@ describe( 'ListCommand', () => {
 
 		command = new ListCommand( editor, 'bulleted' );
 
-		model.schema.registerItem( 'listItem', '$block' );
-		model.schema.registerItem( 'paragraph', '$block' );
-		model.schema.registerItem( 'widget', '$block' );
+		model.schema.register( 'listItem', {
+			inheritAllFrom: '$block',
+			allowAttributes: [ 'type', 'indent' ]
+		} );
+		model.schema.register( 'listItem', { inheritAllFrom: '$block' } );
+		model.schema.register( 'paragraph', {
+			inheritAllFrom: '$block',
+			allowIn: 'widget'
+		} );
+		model.schema.register( 'widget', { inheritAllFrom: '$block' } );
 
-		model.schema.allow( { name: '$block', inside: '$root' } );
-		model.schema.allow( { name: 'paragraph', inside: 'widget' } );
-		model.schema.allow( { name: 'listItem', attributes: [ 'type', 'indent' ], inside: '$root' } );
-		model.schema.disallow( { name: 'listItem', attributes: [ 'type', 'indent' ], inside: 'widget' } );
+		// TODO callback if really needed cause this rule is odd
+		// model.schema.xdisallow( { name: 'listItem', attributes: [ 'type', 'indent' ], inside: 'widget' } );
 
 		setData(
 			model,
@@ -248,12 +253,12 @@ describe( 'ListCommand', () => {
 
 				// https://github.com/ckeditor/ckeditor5-list/issues/62
 				it( 'should not rename blocks which cannot become listItems', () => {
-					model.schema.registerItem( 'restricted' );
-					model.schema.allow( { name: 'restricted', inside: '$root' } );
-					model.schema.disallow( { name: 'paragraph', inside: 'restricted' } );
+					model.schema.register( 'restricted' );
+					model.schema.extend( 'restricted', { allowIn: '$root' } );
+					model.schema.dis.extend( 'paragraph', { allowIn: 'restricted' } );
 
-					model.schema.registerItem( 'fooBlock', '$block' );
-					model.schema.allow( { name: 'fooBlock', inside: 'restricted' } );
+					model.schema.register( 'fooBlock', { inheritAllFrom: '$block' } );
+					model.schema.extend( 'fooBlock', { allowIn: 'restricted' } );
 
 					setData(
 						model,

+ 3 - 3
packages/ckeditor5-list/tests/listengine.js

@@ -51,10 +51,10 @@ describe( 'ListEngine', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.hasItem( 'listItem' ) );
-		expect( model.schema.itemExtends( 'listItem', '$block' ) );
+		expect( model.schema.isRegistered( 'listItem' ) );
+		expect( model.schema.isBlock( 'listItem' ) );
 
-		expect( model.schema.check( { name: '$inline', inside: 'listItem' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$text', inside: 'listItem' } ) ).to.be.true;
 		expect( model.schema.check( { name: 'listItem', inside: 'listItem' } ) ).to.be.false;
 		expect( model.schema.check( { name: '$block', inside: 'listItem' } ) ).to.be.false;