|
@@ -19,15 +19,12 @@ import ModelText from '../../src/model/text';
|
|
|
import ModelRange from '../../src/model/range';
|
|
import ModelRange from '../../src/model/range';
|
|
|
import ModelPosition from '../../src/model/position';
|
|
import ModelPosition from '../../src/model/position';
|
|
|
|
|
|
|
|
-import {
|
|
|
|
|
- upcastElementToElement, upcastElementToAttribute, upcastAttributeToAttribute, upcastElementToMarker,
|
|
|
|
|
- convertToModelFragment, convertText
|
|
|
|
|
-} from '../../src/conversion/upcast-converters';
|
|
|
|
|
|
|
+import UpcastHelpers, { convertToModelFragment, convertText } from '../../src/conversion/upcasthelpers';
|
|
|
|
|
|
|
|
import { stringify } from '../../src/dev-utils/model';
|
|
import { stringify } from '../../src/dev-utils/model';
|
|
|
|
|
|
|
|
-describe( 'upcast-helpers', () => {
|
|
|
|
|
- let upcastDispatcher, model, schema, conversion;
|
|
|
|
|
|
|
+describe( 'UpcastHelpers', () => {
|
|
|
|
|
+ let upcastDispatcher, model, schema, conversion, upcastHelpers;
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
model = new Model();
|
|
model = new Model();
|
|
@@ -49,14 +46,17 @@ describe( 'upcast-helpers', () => {
|
|
|
upcastDispatcher.on( 'documentFragment', convertToModelFragment(), { priority: 'lowest' } );
|
|
upcastDispatcher.on( 'documentFragment', convertToModelFragment(), { priority: 'lowest' } );
|
|
|
|
|
|
|
|
conversion = new Conversion();
|
|
conversion = new Conversion();
|
|
|
- conversion.register( 'upcast', [ upcastDispatcher ] );
|
|
|
|
|
|
|
+ upcastHelpers = new UpcastHelpers( upcastDispatcher );
|
|
|
|
|
+ conversion.register( 'upcast', upcastHelpers );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'upcastElementToElement', () => {
|
|
|
|
|
- it( 'config.view is a string', () => {
|
|
|
|
|
- const helper = upcastElementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
|
|
+ describe( '.elementToElement()', () => {
|
|
|
|
|
+ it( 'should be chainable', () => {
|
|
|
|
|
+ expect( upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } ) ).to.equal( upcastHelpers );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ it( 'config.view is a string', () => {
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
|
|
|
expectResult( new ViewContainerElement( 'p' ), '<paragraph></paragraph>' );
|
|
expectResult( new ViewContainerElement( 'p' ), '<paragraph></paragraph>' );
|
|
|
} );
|
|
} );
|
|
@@ -66,10 +66,8 @@ describe( 'upcast-helpers', () => {
|
|
|
inheritAllFrom: '$block'
|
|
inheritAllFrom: '$block'
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helperA = upcastElementToElement( { view: 'p', model: 'p' } );
|
|
|
|
|
- const helperB = upcastElementToElement( { view: 'p', model: 'paragraph', converterPriority: 'high' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperA ).add( helperB );
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'p', model: 'p' } );
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'p', model: 'paragraph', converterPriority: 'high' } );
|
|
|
|
|
|
|
|
expectResult( new ViewContainerElement( 'p' ), '<paragraph></paragraph>' );
|
|
expectResult( new ViewContainerElement( 'p' ), '<paragraph></paragraph>' );
|
|
|
} );
|
|
} );
|
|
@@ -79,16 +77,14 @@ describe( 'upcast-helpers', () => {
|
|
|
inheritAllFrom: '$block'
|
|
inheritAllFrom: '$block'
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helperFancy = upcastElementToElement( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( {
|
|
|
view: {
|
|
view: {
|
|
|
name: 'p',
|
|
name: 'p',
|
|
|
classes: 'fancy'
|
|
classes: 'fancy'
|
|
|
},
|
|
},
|
|
|
- model: 'fancyParagraph',
|
|
|
|
|
|
|
+ model: 'fancyParagraph'
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperFancy );
|
|
|
|
|
-
|
|
|
|
|
expectResult( new ViewContainerElement( 'p', { class: 'fancy' } ), '<fancyParagraph></fancyParagraph>' );
|
|
expectResult( new ViewContainerElement( 'p', { class: 'fancy' } ), '<fancyParagraph></fancyParagraph>' );
|
|
|
expectResult( new ViewContainerElement( 'p' ), '' );
|
|
expectResult( new ViewContainerElement( 'p' ), '' );
|
|
|
} );
|
|
} );
|
|
@@ -99,7 +95,7 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'level' ]
|
|
allowAttributes: [ 'level' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helper = upcastElementToElement( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( {
|
|
|
view: {
|
|
view: {
|
|
|
name: 'p',
|
|
name: 'p',
|
|
|
classes: 'heading'
|
|
classes: 'heading'
|
|
@@ -109,24 +105,18 @@ describe( 'upcast-helpers', () => {
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
-
|
|
|
|
|
expectResult( new ViewContainerElement( 'p', { class: 'heading', 'data-level': 2 } ), '<heading level="2"></heading>' );
|
|
expectResult( new ViewContainerElement( 'p', { class: 'heading', 'data-level': 2 } ), '<heading level="2"></heading>' );
|
|
|
expectResult( new ViewContainerElement( 'p', { 'data-level': 2 } ), '' );
|
|
expectResult( new ViewContainerElement( 'p', { 'data-level': 2 } ), '' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should fire conversion of the element children', () => {
|
|
it( 'should fire conversion of the element children', () => {
|
|
|
- const helper = upcastElementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
|
|
|
expectResult( new ViewContainerElement( 'p', null, new ViewText( 'foo' ) ), '<paragraph>foo</paragraph>' );
|
|
expectResult( new ViewContainerElement( 'p', null, new ViewText( 'foo' ) ), '<paragraph>foo</paragraph>' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not insert a model element if it is not allowed by schema', () => {
|
|
it( 'should not insert a model element if it is not allowed by schema', () => {
|
|
|
- const helper = upcastElementToElement( { view: 'h2', model: 'heading' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'h2', model: 'heading' } );
|
|
|
|
|
|
|
|
expectResult( new ViewContainerElement( 'h2' ), '' );
|
|
expectResult( new ViewContainerElement( 'h2' ), '' );
|
|
|
} );
|
|
} );
|
|
@@ -136,10 +126,8 @@ describe( 'upcast-helpers', () => {
|
|
|
inheritAllFrom: '$block'
|
|
inheritAllFrom: '$block'
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helperParagraph = upcastElementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
- const helperHeading = upcastElementToElement( { view: 'h2', model: 'heading' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperParagraph ).add( helperHeading );
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'h2', model: 'heading' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewContainerElement( 'p', null, [
|
|
new ViewContainerElement( 'p', null, [
|
|
@@ -152,20 +140,20 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not do anything if returned model element is null', () => {
|
|
it( 'should not do anything if returned model element is null', () => {
|
|
|
- const helperA = upcastElementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
- const helperB = upcastElementToElement( { view: 'p', model: () => null, converterPriority: 'high' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperA ).add( helperB );
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'p', model: () => null, converterPriority: 'high' } );
|
|
|
|
|
|
|
|
expectResult( new ViewContainerElement( 'p' ), '<paragraph></paragraph>' );
|
|
expectResult( new ViewContainerElement( 'p' ), '<paragraph></paragraph>' );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'upcastElementToAttribute', () => {
|
|
|
|
|
- it( 'config.view is string', () => {
|
|
|
|
|
- const helper = upcastElementToAttribute( { view: 'strong', model: 'bold' } );
|
|
|
|
|
|
|
+ describe( '.elementToAttribute()', () => {
|
|
|
|
|
+ it( 'should be chainable', () => {
|
|
|
|
|
+ expect( upcastHelpers.elementToAttribute( { view: 'strong', model: 'bold' } ) ).to.equal( upcastHelpers );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ it( 'config.view is string', () => {
|
|
|
|
|
+ upcastHelpers.elementToAttribute( { view: 'strong', model: 'bold' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'strong', null, new ViewText( 'foo' ) ),
|
|
new ViewAttributeElement( 'strong', null, new ViewText( 'foo' ) ),
|
|
@@ -174,10 +162,8 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'can be overwritten using converterPriority', () => {
|
|
it( 'can be overwritten using converterPriority', () => {
|
|
|
- const helperA = upcastElementToAttribute( { view: 'strong', model: 'strong' } );
|
|
|
|
|
- const helperB = upcastElementToAttribute( { view: 'strong', model: 'bold', converterPriority: 'high' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperA ).add( helperB );
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( { view: 'strong', model: 'strong' } );
|
|
|
|
|
+ upcastHelpers.elementToAttribute( { view: 'strong', model: 'bold', converterPriority: 'high' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'strong', null, new ViewText( 'foo' ) ),
|
|
new ViewAttributeElement( 'strong', null, new ViewText( 'foo' ) ),
|
|
@@ -186,7 +172,7 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'config.view is an object', () => {
|
|
it( 'config.view is an object', () => {
|
|
|
- const helper = upcastElementToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( {
|
|
|
view: {
|
|
view: {
|
|
|
name: 'span',
|
|
name: 'span',
|
|
|
classes: 'bold'
|
|
classes: 'bold'
|
|
@@ -194,8 +180,6 @@ describe( 'upcast-helpers', () => {
|
|
|
model: 'bold'
|
|
model: 'bold'
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
-
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'span', { class: 'bold' }, new ViewText( 'foo' ) ),
|
|
new ViewAttributeElement( 'span', { class: 'bold' }, new ViewText( 'foo' ) ),
|
|
|
'<$text bold="true">foo</$text>'
|
|
'<$text bold="true">foo</$text>'
|
|
@@ -209,7 +193,7 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'styled' ]
|
|
allowAttributes: [ 'styled' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helper = upcastElementToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( {
|
|
|
view: {
|
|
view: {
|
|
|
name: 'span',
|
|
name: 'span',
|
|
|
classes: [ 'styled', 'styled-dark' ]
|
|
classes: [ 'styled', 'styled-dark' ]
|
|
@@ -220,8 +204,6 @@ describe( 'upcast-helpers', () => {
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
-
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'span', { class: 'styled styled-dark' }, new ViewText( 'foo' ) ),
|
|
new ViewAttributeElement( 'span', { class: 'styled styled-dark' }, new ViewText( 'foo' ) ),
|
|
|
'<$text styled="dark">foo</$text>'
|
|
'<$text styled="dark">foo</$text>'
|
|
@@ -235,7 +217,7 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'fontSize' ]
|
|
allowAttributes: [ 'fontSize' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helper = upcastElementToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( {
|
|
|
view: {
|
|
view: {
|
|
|
name: 'span',
|
|
name: 'span',
|
|
|
styles: {
|
|
styles: {
|
|
@@ -259,8 +241,6 @@ describe( 'upcast-helpers', () => {
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
-
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'span', { style: 'font-size:9px' }, new ViewText( 'foo' ) ),
|
|
new ViewAttributeElement( 'span', { style: 'font-size:9px' }, new ViewText( 'foo' ) ),
|
|
|
'<$text fontSize="small">foo</$text>'
|
|
'<$text fontSize="small">foo</$text>'
|
|
@@ -278,9 +258,7 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not set an attribute if it is not allowed by schema', () => {
|
|
it( 'should not set an attribute if it is not allowed by schema', () => {
|
|
|
- const helper = upcastElementToAttribute( { view: 'em', model: 'italic' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( { view: 'em', model: 'italic' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'em', null, new ViewText( 'foo' ) ),
|
|
new ViewAttributeElement( 'em', null, new ViewText( 'foo' ) ),
|
|
@@ -289,8 +267,8 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not do anything if returned model attribute is null', () => {
|
|
it( 'should not do anything if returned model attribute is null', () => {
|
|
|
- const helperA = upcastElementToAttribute( { view: 'strong', model: 'bold' } );
|
|
|
|
|
- const helperB = upcastElementToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( { view: 'strong', model: 'bold' } );
|
|
|
|
|
+ upcastHelpers.elementToAttribute( {
|
|
|
view: 'strong',
|
|
view: 'strong',
|
|
|
model: {
|
|
model: {
|
|
|
key: 'bold',
|
|
key: 'bold',
|
|
@@ -299,8 +277,6 @@ describe( 'upcast-helpers', () => {
|
|
|
converterPriority: 'high'
|
|
converterPriority: 'high'
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperA ).add( helperB );
|
|
|
|
|
-
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'strong', null, new ViewText( 'foo' ) ),
|
|
new ViewAttributeElement( 'strong', null, new ViewText( 'foo' ) ),
|
|
|
'<$text bold="true">foo</$text>'
|
|
'<$text bold="true">foo</$text>'
|
|
@@ -308,18 +284,16 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should allow two converters to convert attributes on the same element', () => {
|
|
it( 'should allow two converters to convert attributes on the same element', () => {
|
|
|
- const helperA = upcastElementToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( {
|
|
|
model: 'attribA',
|
|
model: 'attribA',
|
|
|
view: { name: 'span', classes: 'attrib-a' }
|
|
view: { name: 'span', classes: 'attrib-a' }
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helperB = upcastElementToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( {
|
|
|
model: 'attribB',
|
|
model: 'attribB',
|
|
|
view: { name: 'span', styles: { color: 'attrib-b' } }
|
|
view: { name: 'span', styles: { color: 'attrib-b' } }
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperA ).add( helperB );
|
|
|
|
|
-
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'span', { class: 'attrib-a', style: 'color:attrib-b;' }, new ViewText( 'foo' ) ),
|
|
new ViewAttributeElement( 'span', { class: 'attrib-a', style: 'color:attrib-b;' }, new ViewText( 'foo' ) ),
|
|
|
'<$text attribA="true" attribB="true">foo</$text>'
|
|
'<$text attribA="true" attribB="true">foo</$text>'
|
|
@@ -327,23 +301,21 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should consume element only when only is name specified', () => {
|
|
it( 'should consume element only when only is name specified', () => {
|
|
|
- const helperBold = upcastElementToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( {
|
|
|
model: 'bold',
|
|
model: 'bold',
|
|
|
view: { name: 'strong' }
|
|
view: { name: 'strong' }
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helperA = upcastElementToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( {
|
|
|
model: 'attribA',
|
|
model: 'attribA',
|
|
|
view: { name: 'strong' }
|
|
view: { name: 'strong' }
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helperB = upcastElementToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( {
|
|
|
model: 'attribB',
|
|
model: 'attribB',
|
|
|
view: { name: 'strong', classes: 'foo' }
|
|
view: { name: 'strong', classes: 'foo' }
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperBold ).add( helperA ).add( helperB );
|
|
|
|
|
-
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'strong', { class: 'foo' }, new ViewText( 'foo' ) ),
|
|
new ViewAttributeElement( 'strong', { class: 'foo' }, new ViewText( 'foo' ) ),
|
|
|
'<$text attribB="true" bold="true">foo</$text>'
|
|
'<$text attribB="true" bold="true">foo</$text>'
|
|
@@ -352,14 +324,12 @@ describe( 'upcast-helpers', () => {
|
|
|
|
|
|
|
|
// #1443.
|
|
// #1443.
|
|
|
it( 'should set attributes on the element\'s children', () => {
|
|
it( 'should set attributes on the element\'s children', () => {
|
|
|
- const helperBold = upcastElementToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToAttribute( {
|
|
|
model: 'bold',
|
|
model: 'bold',
|
|
|
view: { name: 'strong' }
|
|
view: { name: 'strong' }
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helperP = upcastElementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperP ).add( helperBold );
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement(
|
|
new ViewAttributeElement(
|
|
@@ -372,23 +342,25 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'upcastAttributeToAttribute', () => {
|
|
|
|
|
|
|
+ describe( '.attributeToAttribute()', () => {
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
- conversion.for( 'upcast' ).add( upcastElementToElement( { view: 'img', model: 'image' } ) );
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'img', model: 'image' } );
|
|
|
|
|
|
|
|
schema.register( 'image', {
|
|
schema.register( 'image', {
|
|
|
inheritAllFrom: '$block'
|
|
inheritAllFrom: '$block'
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should be chainable', () => {
|
|
|
|
|
+ expect( upcastHelpers.attributeToAttribute( { view: 'src', model: 'source' } ) ).to.equal( upcastHelpers );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'config.view is a string', () => {
|
|
it( 'config.view is a string', () => {
|
|
|
schema.extend( 'image', {
|
|
schema.extend( 'image', {
|
|
|
allowAttributes: [ 'source' ]
|
|
allowAttributes: [ 'source' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helper = upcastAttributeToAttribute( { view: 'src', model: 'source' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( { view: 'src', model: 'source' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'img', { src: 'foo.jpg' } ),
|
|
new ViewAttributeElement( 'img', { src: 'foo.jpg' } ),
|
|
@@ -401,9 +373,7 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'source' ]
|
|
allowAttributes: [ 'source' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helper = upcastAttributeToAttribute( { view: { key: 'src' }, model: 'source' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( { view: { key: 'src' }, model: 'source' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'img', { src: 'foo.jpg' } ),
|
|
new ViewAttributeElement( 'img', { src: 'foo.jpg' } ),
|
|
@@ -416,9 +386,7 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'source' ]
|
|
allowAttributes: [ 'source' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helper = upcastAttributeToAttribute( { view: { name: 'img', key: 'src' }, model: { name: 'image', key: 'source' } } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( { view: { name: 'img', key: 'src' }, model: { name: 'image', key: 'source' } } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'img', { src: 'foo.jpg' } ),
|
|
new ViewAttributeElement( 'img', { src: 'foo.jpg' } ),
|
|
@@ -431,10 +399,8 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'src', 'source' ]
|
|
allowAttributes: [ 'src', 'source' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helperA = upcastAttributeToAttribute( { view: { key: 'src' }, model: 'src' } );
|
|
|
|
|
- const helperB = upcastAttributeToAttribute( { view: { key: 'src' }, model: 'source', converterPriority: 'normal' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperA ).add( helperB );
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( { view: { key: 'src' }, model: 'src' } );
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( { view: { key: 'src' }, model: 'source', converterPriority: 'normal' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'img', { src: 'foo.jpg' } ),
|
|
new ViewAttributeElement( 'img', { src: 'foo.jpg' } ),
|
|
@@ -447,7 +413,7 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'styled' ]
|
|
allowAttributes: [ 'styled' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helper = upcastAttributeToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( {
|
|
|
view: {
|
|
view: {
|
|
|
key: 'data-style',
|
|
key: 'data-style',
|
|
|
value: /[\s\S]*/
|
|
value: /[\s\S]*/
|
|
@@ -455,8 +421,6 @@ describe( 'upcast-helpers', () => {
|
|
|
model: 'styled'
|
|
model: 'styled'
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
-
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'img', { 'data-style': 'dark' } ),
|
|
new ViewAttributeElement( 'img', { 'data-style': 'dark' } ),
|
|
|
'<image styled="dark"></image>'
|
|
'<image styled="dark"></image>'
|
|
@@ -468,7 +432,7 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'styled' ]
|
|
allowAttributes: [ 'styled' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helper = upcastAttributeToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( {
|
|
|
view: {
|
|
view: {
|
|
|
name: 'img',
|
|
name: 'img',
|
|
|
key: 'class',
|
|
key: 'class',
|
|
@@ -480,9 +444,7 @@ describe( 'upcast-helpers', () => {
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' )
|
|
|
|
|
- .add( helper )
|
|
|
|
|
- .add( upcastElementToElement( { view: 'p', model: 'paragraph' } ) );
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewContainerElement( 'img', { class: 'styled-dark' } ),
|
|
new ViewContainerElement( 'img', { class: 'styled-dark' } ),
|
|
@@ -505,7 +467,7 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'styled' ]
|
|
allowAttributes: [ 'styled' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helper = upcastAttributeToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( {
|
|
|
view: {
|
|
view: {
|
|
|
key: 'class',
|
|
key: 'class',
|
|
|
value: /styled-[\S]+/
|
|
value: /styled-[\S]+/
|
|
@@ -521,8 +483,6 @@ describe( 'upcast-helpers', () => {
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
-
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'img', { 'class': 'styled-dark' } ),
|
|
new ViewAttributeElement( 'img', { 'class': 'styled-dark' } ),
|
|
|
'<image styled="dark"></image>'
|
|
'<image styled="dark"></image>'
|
|
@@ -530,9 +490,7 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not set an attribute if it is not allowed by schema', () => {
|
|
it( 'should not set an attribute if it is not allowed by schema', () => {
|
|
|
- const helper = upcastAttributeToAttribute( { view: 'src', model: 'source' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( { view: 'src', model: 'source' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'img', { src: 'foo.jpg' } ),
|
|
new ViewAttributeElement( 'img', { src: 'foo.jpg' } ),
|
|
@@ -545,7 +503,7 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'styled' ]
|
|
allowAttributes: [ 'styled' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helperA = upcastAttributeToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( {
|
|
|
view: {
|
|
view: {
|
|
|
key: 'class',
|
|
key: 'class',
|
|
|
value: 'styled'
|
|
value: 'styled'
|
|
@@ -556,7 +514,7 @@ describe( 'upcast-helpers', () => {
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const helperB = upcastAttributeToAttribute( {
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( {
|
|
|
view: {
|
|
view: {
|
|
|
key: 'class',
|
|
key: 'class',
|
|
|
value: 'styled'
|
|
value: 'styled'
|
|
@@ -567,8 +525,6 @@ describe( 'upcast-helpers', () => {
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperA ).add( helperB );
|
|
|
|
|
-
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewAttributeElement( 'img', { class: 'styled' } ),
|
|
new ViewAttributeElement( 'img', { class: 'styled' } ),
|
|
|
'<image styled="true"></image>'
|
|
'<image styled="true"></image>'
|
|
@@ -584,13 +540,10 @@ describe( 'upcast-helpers', () => {
|
|
|
allowAttributes: [ 'border', 'shade' ]
|
|
allowAttributes: [ 'border', 'shade' ]
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( upcastElementToElement( { view: 'div', model: 'div' } ) );
|
|
|
|
|
-
|
|
|
|
|
- const shadeHelper = upcastAttributeToAttribute( { view: { key: 'class', value: 'shade' }, model: 'shade' } );
|
|
|
|
|
- const borderHelper = upcastAttributeToAttribute( { view: { key: 'class', value: 'border' }, model: 'border' } );
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( { view: 'div', model: 'div' } );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( shadeHelper );
|
|
|
|
|
- conversion.for( 'upcast' ).add( borderHelper );
|
|
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( { view: { key: 'class', value: 'shade' }, model: 'shade' } );
|
|
|
|
|
+ upcastHelpers.attributeToAttribute( { view: { key: 'class', value: 'border' }, model: 'border' } );
|
|
|
|
|
|
|
|
expectResult(
|
|
expectResult(
|
|
|
new ViewContainerElement(
|
|
new ViewContainerElement(
|
|
@@ -603,11 +556,13 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'upcastElementToMarker', () => {
|
|
|
|
|
- it( 'config.view is a string', () => {
|
|
|
|
|
- const helper = upcastElementToMarker( { view: 'marker-search', model: 'search' } );
|
|
|
|
|
|
|
+ describe( '.elementToMarker()', () => {
|
|
|
|
|
+ it( 'should be chainable', () => {
|
|
|
|
|
+ expect( upcastHelpers.elementToMarker( { view: 'marker-search', model: 'search' } ) ).to.equal( upcastHelpers );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ it( 'config.view is a string', () => {
|
|
|
|
|
+ upcastHelpers.elementToMarker( { view: 'marker-search', model: 'search' } );
|
|
|
|
|
|
|
|
const frag = new ViewDocumentFragment( [
|
|
const frag = new ViewDocumentFragment( [
|
|
|
new ViewText( 'fo' ),
|
|
new ViewText( 'fo' ),
|
|
@@ -623,10 +578,8 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'can be overwritten using converterPriority', () => {
|
|
it( 'can be overwritten using converterPriority', () => {
|
|
|
- const helperA = upcastElementToMarker( { view: 'marker-search', model: 'search-result' } );
|
|
|
|
|
- const helperB = upcastElementToMarker( { view: 'marker-search', model: 'search', converterPriority: 'high' } );
|
|
|
|
|
-
|
|
|
|
|
- conversion.for( 'upcast' ).add( helperA ).add( helperB );
|
|
|
|
|
|
|
+ upcastHelpers.elementToMarker( { view: 'marker-search', model: 'search-result' } );
|
|
|
|
|
+ upcastHelpers.elementToMarker( { view: 'marker-search', model: 'search', converterPriority: 'high' } );
|
|
|
|
|
|
|
|
const frag = new ViewDocumentFragment( [
|
|
const frag = new ViewDocumentFragment( [
|
|
|
new ViewText( 'fo' ),
|
|
new ViewText( 'fo' ),
|
|
@@ -642,7 +595,7 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'config.view is an object', () => {
|
|
it( 'config.view is an object', () => {
|
|
|
- const helper = upcastElementToMarker( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToMarker( {
|
|
|
view: {
|
|
view: {
|
|
|
name: 'span',
|
|
name: 'span',
|
|
|
'data-marker': 'search'
|
|
'data-marker': 'search'
|
|
@@ -650,8 +603,6 @@ describe( 'upcast-helpers', () => {
|
|
|
model: 'search'
|
|
model: 'search'
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
-
|
|
|
|
|
const frag = new ViewDocumentFragment( [
|
|
const frag = new ViewDocumentFragment( [
|
|
|
new ViewText( 'f' ),
|
|
new ViewText( 'f' ),
|
|
|
new ViewUIElement( 'span', { 'data-marker': 'search' } ),
|
|
new ViewUIElement( 'span', { 'data-marker': 'search' } ),
|
|
@@ -666,13 +617,11 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'config.model is a function', () => {
|
|
it( 'config.model is a function', () => {
|
|
|
- const helper = upcastElementToMarker( {
|
|
|
|
|
|
|
+ upcastHelpers.elementToMarker( {
|
|
|
view: 'comment',
|
|
view: 'comment',
|
|
|
model: viewElement => 'comment:' + viewElement.getAttribute( 'data-comment-id' )
|
|
model: viewElement => 'comment:' + viewElement.getAttribute( 'data-comment-id' )
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
-
|
|
|
|
|
const frag = new ViewDocumentFragment( [
|
|
const frag = new ViewDocumentFragment( [
|
|
|
new ViewText( 'foo' ),
|
|
new ViewText( 'foo' ),
|
|
|
new ViewUIElement( 'comment', { 'data-comment-id': 4 } ),
|
|
new ViewUIElement( 'comment', { 'data-comment-id': 4 } ),
|
|
@@ -687,11 +636,9 @@ describe( 'upcast-helpers', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'marker is in a block element', () => {
|
|
it( 'marker is in a block element', () => {
|
|
|
- conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'paragraph', view: 'p' } ) );
|
|
|
|
|
-
|
|
|
|
|
- const helper = upcastElementToMarker( { view: 'marker-search', model: 'search' } );
|
|
|
|
|
|
|
+ upcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
|
|
|
|
|
|
|
|
- conversion.for( 'upcast' ).add( helper );
|
|
|
|
|
|
|
+ upcastHelpers.elementToMarker( { view: 'marker-search', model: 'search' } );
|
|
|
|
|
|
|
|
const element = new ViewContainerElement( 'p', null, [
|
|
const element = new ViewContainerElement( 'p', null, [
|
|
|
new ViewText( 'fo' ),
|
|
new ViewText( 'fo' ),
|