|
|
@@ -161,7 +161,7 @@ describe( 'Schema', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'ensures no unregistered items in allowIn', () => {
|
|
|
+ it( 'ensures no non-registered items in allowIn', () => {
|
|
|
schema.register( 'foo', {
|
|
|
allowIn: '$root'
|
|
|
} );
|
|
|
@@ -256,7 +256,7 @@ describe( 'Schema', () => {
|
|
|
expect( schema.getDefinition( ctx.last ).isMe ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
- it( 'returns undefined when trying to get an unregistered item', () => {
|
|
|
+ it( 'returns undefined when trying to get an non-registered item', () => {
|
|
|
expect( schema.getDefinition( '404' ) ).to.be.undefined;
|
|
|
} );
|
|
|
} );
|
|
|
@@ -498,6 +498,84 @@ describe( 'Schema', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
+ describe( 'addChildCheck()', () => {
|
|
|
+ beforeEach( () => {
|
|
|
+ schema.register( '$root' );
|
|
|
+ schema.register( 'paragraph', {
|
|
|
+ allowIn: '$root'
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'adds a high-priority listener', () => {
|
|
|
+ const order = [];
|
|
|
+
|
|
|
+ schema.on( 'checkChild', () => {
|
|
|
+ order.push( 'checkChild:high-before' );
|
|
|
+ }, { priority: 'high' } );
|
|
|
+
|
|
|
+ schema.addChildCheck( () => {
|
|
|
+ order.push( 'addChildCheck' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ schema.on( 'checkChild', () => {
|
|
|
+ order.push( 'checkChild:high-after' );
|
|
|
+ }, { priority: 'high' } );
|
|
|
+
|
|
|
+ schema.checkChild( root1, r1p1 );
|
|
|
+
|
|
|
+ expect( order.join() ).to.equal( 'checkChild:high-before,addChildCheck,checkChild:high-after' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'stops the event and overrides the return value when callback returned true', () => {
|
|
|
+ schema.register( '$text' );
|
|
|
+
|
|
|
+ expect( schema.checkChild( root1, '$text' ) ).to.be.false;
|
|
|
+
|
|
|
+ schema.addChildCheck( () => {
|
|
|
+ return true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ schema.on( 'checkChild', () => {
|
|
|
+ throw new Error( 'the event should be stopped' );
|
|
|
+ }, { priority: 'high' } );
|
|
|
+
|
|
|
+ expect( schema.checkChild( root1, '$text' ) ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'stops the event and overrides the return value when callback returned false', () => {
|
|
|
+ expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
|
|
|
+
|
|
|
+ schema.addChildCheck( () => {
|
|
|
+ return false;
|
|
|
+ } );
|
|
|
+
|
|
|
+ schema.on( 'checkChild', () => {
|
|
|
+ throw new Error( 'the event should be stopped' );
|
|
|
+ }, { priority: 'high' } );
|
|
|
+
|
|
|
+ expect( schema.checkChild( root1, r1p1 ) ).to.be.false;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'receives context and child definition as params', () => {
|
|
|
+ schema.addChildCheck( ( ctx, childDef ) => {
|
|
|
+ expect( ctx ).to.be.instanceOf( SchemaContext );
|
|
|
+ expect( childDef ).to.equal( schema.getDefinition( 'paragraph' ) );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'is not called when checking a non-registered element', () => {
|
|
|
+ expect( schema.getDefinition( 'foo' ) ).to.be.undefined;
|
|
|
+
|
|
|
+ schema.addChildCheck( () => {
|
|
|
+ throw new Error( 'callback should not be called' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( schema.checkChild( root1, 'foo' ) ).to.be.false;
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'getLimitElement()', () => {
|
|
|
let model, doc, root;
|
|
|
|
|
|
@@ -1001,7 +1079,7 @@ describe( 'Schema', () => {
|
|
|
expect( schema.checkChild( div, div ) ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
- it( 'rejects $root>paragraph – unregistered paragraph', () => {
|
|
|
+ it( 'rejects $root>paragraph – non-registered paragraph', () => {
|
|
|
schema.register( '$root' );
|
|
|
|
|
|
expect( schema.checkChild( root1, r1p1 ) ).to.be.false;
|
|
|
@@ -1430,7 +1508,7 @@ describe( 'Schema', () => {
|
|
|
expect( schema.checkChild( root1, 'foo404' ) ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
- it( 'does not break when trying to check registered child in a context which contains unregistered elements', () => {
|
|
|
+ it( 'does not break when trying to check registered child in a context which contains non-registered elements', () => {
|
|
|
const foo404 = new Element( 'foo404' );
|
|
|
|
|
|
root1.appendChildren( foo404 );
|
|
|
@@ -1443,7 +1521,7 @@ describe( 'Schema', () => {
|
|
|
expect( schema.checkChild( foo404, '$text' ) ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
- it( 'does not break when used allowedIn pointing to an unregistered element', () => {
|
|
|
+ it( 'does not break when used allowedIn pointing to an non-registered element', () => {
|
|
|
schema.register( '$root' );
|
|
|
schema.register( '$text', {
|
|
|
allowIn: 'foo404'
|
|
|
@@ -1452,7 +1530,7 @@ describe( 'Schema', () => {
|
|
|
expect( schema.checkChild( root1, '$text' ) ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
- it( 'does not break when used allowWhere pointing to an unregistered element', () => {
|
|
|
+ it( 'does not break when used allowWhere pointing to an non-registered element', () => {
|
|
|
schema.register( '$root' );
|
|
|
schema.register( '$text', {
|
|
|
allowWhere: 'foo404'
|
|
|
@@ -1461,7 +1539,7 @@ describe( 'Schema', () => {
|
|
|
expect( schema.checkChild( root1, '$text' ) ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
- it( 'does not break when used allowContentOf pointing to an unregistered element', () => {
|
|
|
+ it( 'does not break when used allowContentOf pointing to an non-registered element', () => {
|
|
|
schema.register( '$root', {
|
|
|
allowContentOf: 'foo404'
|
|
|
} );
|
|
|
@@ -1481,7 +1559,7 @@ describe( 'Schema', () => {
|
|
|
expect( schema.checkChild( root1, 'paragraph' ) ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
- it( 'does not break when inheriting all from an unregistered element', () => {
|
|
|
+ it( 'does not break when inheriting all from an non-registered element', () => {
|
|
|
schema.register( 'paragraph', {
|
|
|
inheritAllFrom: '$block'
|
|
|
} );
|
|
|
@@ -1591,11 +1669,11 @@ describe( 'Schema', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'missing attribute definitions', () => {
|
|
|
- it( 'does not crash when checking an attribute of a unregistered element', () => {
|
|
|
+ it( 'does not crash when checking an attribute of a non-registered element', () => {
|
|
|
expect( schema.checkAttribute( r1p1, 'align' ) ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
- it( 'does not crash when inheriting attributes of a unregistered element', () => {
|
|
|
+ it( 'does not crash when inheriting attributes of a non-registered element', () => {
|
|
|
schema.register( 'paragraph', {
|
|
|
allowAttributesOf: '$block'
|
|
|
} );
|
|
|
@@ -1603,7 +1681,7 @@ describe( 'Schema', () => {
|
|
|
expect( schema.checkAttribute( r1p1, 'whatever' ) ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
- it( 'does not crash when inheriting all from a unregistered element', () => {
|
|
|
+ it( 'does not crash when inheriting all from a non-registered element', () => {
|
|
|
schema.register( 'paragraph', {
|
|
|
allowAttributesOf: '$block'
|
|
|
} );
|
|
|
@@ -1613,7 +1691,7 @@ describe( 'Schema', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'missing types definitions', () => {
|
|
|
- it( 'does not crash when inheriting types of an unregistered element', () => {
|
|
|
+ it( 'does not crash when inheriting types of an non-registered element', () => {
|
|
|
schema.register( 'paragraph', {
|
|
|
inheritTypesFrom: '$block'
|
|
|
} );
|
|
|
@@ -1650,15 +1728,11 @@ describe( 'Schema', () => {
|
|
|
} );
|
|
|
|
|
|
// Disallow blockQuote in blockQuote.
|
|
|
- schema.on( 'checkChild', ( evt, args ) => {
|
|
|
- const ctx = args[ 0 ];
|
|
|
- const childRule = args[ 1 ];
|
|
|
-
|
|
|
- if ( childRule.name == 'blockQuote' && ctx.endsWith( 'blockQuote' ) ) {
|
|
|
- evt.stop();
|
|
|
- evt.return = false;
|
|
|
+ schema.addChildCheck( ( ctx, childDef ) => {
|
|
|
+ if ( childDef.name == 'blockQuote' && ctx.endsWith( 'blockQuote' ) ) {
|
|
|
+ return false;
|
|
|
}
|
|
|
- }, { priority: 'high' } );
|
|
|
+ } );
|
|
|
},
|
|
|
() => {
|
|
|
schema.register( 'image', {
|