Преглед изворни кода

Change prefix from linkDecorator to link, make first letter of decorator uppercase for better readability. Fix all occurance related to this change.

Mateusz Samsel пре 6 година
родитељ
комит
d254e8dea3

+ 2 - 1
packages/ckeditor5-link/package.json

@@ -12,7 +12,8 @@
   "dependencies": {
     "@ckeditor/ckeditor5-core": "^12.1.1",
     "@ckeditor/ckeditor5-engine": "^13.1.1",
-    "@ckeditor/ckeditor5-ui": "^13.0.0"
+    "@ckeditor/ckeditor5-ui": "^13.0.0",
+    "lodash-es": "^4.17.10"
   },
   "devDependencies": {
     "@ckeditor/ckeditor5-clipboard": "^11.0.2",

+ 1 - 1
packages/ckeditor5-link/src/linkediting.js

@@ -108,7 +108,7 @@ export default class LinkEditing extends Plugin {
 		// Adds default decorator for external links.
 		if ( editor.config.get( 'link.addTargetToExternalLinks' ) ) {
 			automaticDecorators.add( {
-				id: 'linkDecoratorIsExternal',
+				id: 'linkIsExternal',
 				mode: DECORATOR_AUTOMATIC,
 				callback: url => EXTERNAL_LINKS_REGEXP.test( url ),
 				attributes: {

+ 3 - 1
packages/ckeditor5-link/src/utils.js

@@ -7,6 +7,8 @@
  * @module link/utils
  */
 
+import { upperFirst } from 'lodash-es';
+
 const ATTRIBUTE_WHITESPACES = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g; // eslint-disable-line no-control-regex
 const SAFE_URL = /^(?:(?:https?|ftps?|mailto):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/i;
 
@@ -103,7 +105,7 @@ export function getNormalizedDecorators( editor ) {
 			const decorator = Object.assign(
 				{},
 				value,
-				{ id: `linkDecorator${ key }` }
+				{ id: `link${ upperFirst( key ) }` }
 			);
 			retArray.push( decorator );
 		}

+ 25 - 25
packages/ckeditor5-link/tests/linkcommand.js

@@ -271,14 +271,14 @@ describe( 'LinkCommand', () => {
 					command = new LinkCommand( editor );
 
 					command.manualDecorators.add( new ManualDecorator( {
-						id: 'linkDecoratorIsFoo',
+						id: 'linkIsFoo',
 						label: 'Foo',
 						attributes: {
 							class: 'Foo'
 						}
 					} ) );
 					command.manualDecorators.add( new ManualDecorator( {
-						id: 'linkDecoratorIsBar',
+						id: 'linkIsBar',
 						label: 'Bar',
 						attributes: {
 							target: '_blank'
@@ -287,7 +287,7 @@ describe( 'LinkCommand', () => {
 
 					model.schema.extend( '$text', {
 						allowIn: '$root',
-						allowAttributes: [ 'linkHref', 'linkDecoratorIsFoo', 'linkDecoratorIsBar' ]
+						allowAttributes: [ 'linkHref', 'linkIsFoo', 'linkIsBar' ]
 					} );
 
 					model.schema.register( 'p', { inheritAllFrom: '$block' } );
@@ -302,25 +302,25 @@ describe( 'LinkCommand', () => {
 			it( 'should insert additional attributes to link when it is created', () => {
 				setData( model, 'foo[]bar' );
 
-				command.execute( 'url', { linkDecoratorIsFoo: true, linkDecoratorIsBar: true } );
+				command.execute( 'url', { linkIsFoo: true, linkIsBar: true } );
 
 				expect( getData( model ) ).to
-					.equal( 'foo[<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">url</$text>]bar' );
+					.equal( 'foo[<$text linkHref="url" linkIsBar="true" linkIsFoo="true">url</$text>]bar' );
 			} );
 
 			it( 'should add additional attributes to link when link is modified', () => {
 				setData( model, 'f<$text linkHref="url">o[]oba</$text>r' );
 
-				command.execute( 'url', { linkDecoratorIsFoo: true, linkDecoratorIsBar: true } );
+				command.execute( 'url', { linkIsFoo: true, linkIsBar: true } );
 
 				expect( getData( model ) ).to
-					.equal( 'f[<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">ooba</$text>]r' );
+					.equal( 'f[<$text linkHref="url" linkIsBar="true" linkIsFoo="true">ooba</$text>]r' );
 			} );
 
 			it( 'should remove additional attributes to link if those are falsy', () => {
-				setData( model, 'foo<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">u[]rl</$text>bar' );
+				setData( model, 'foo<$text linkHref="url" linkIsBar="true" linkIsFoo="true">u[]rl</$text>bar' );
 
-				command.execute( 'url', { linkDecoratorIsFoo: false, linkDecoratorIsBar: false } );
+				command.execute( 'url', { linkIsFoo: false, linkIsBar: false } );
 
 				expect( getData( model ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
 			} );
@@ -330,25 +330,25 @@ describe( 'LinkCommand', () => {
 			it( 'should insert additional attributes to link when it is created', () => {
 				setData( model, 'f[ooba]r' );
 
-				command.execute( 'url', { linkDecoratorIsFoo: true, linkDecoratorIsBar: true } );
+				command.execute( 'url', { linkIsFoo: true, linkIsBar: true } );
 
 				expect( getData( model ) ).to
-					.equal( 'f[<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">ooba</$text>]r' );
+					.equal( 'f[<$text linkHref="url" linkIsBar="true" linkIsFoo="true">ooba</$text>]r' );
 			} );
 
 			it( 'should add additional attributes to link when link is modified', () => {
 				setData( model, 'f[<$text linkHref="foo">ooba</$text>]r' );
 
-				command.execute( 'url', { linkDecoratorIsFoo: true, linkDecoratorIsBar: true } );
+				command.execute( 'url', { linkIsFoo: true, linkIsBar: true } );
 
 				expect( getData( model ) ).to
-					.equal( 'f[<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">ooba</$text>]r' );
+					.equal( 'f[<$text linkHref="url" linkIsBar="true" linkIsFoo="true">ooba</$text>]r' );
 			} );
 
 			it( 'should remove additional attributes to link if those are falsy', () => {
-				setData( model, 'foo[<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">url</$text>]bar' );
+				setData( model, 'foo[<$text linkHref="url" linkIsBar="true" linkIsFoo="true">url</$text>]bar' );
 
-				command.execute( 'url', { linkDecoratorIsFoo: false, linkDecoratorIsBar: false } );
+				command.execute( 'url', { linkIsFoo: false, linkIsBar: false } );
 
 				expect( getData( model ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
 			} );
@@ -356,35 +356,35 @@ describe( 'LinkCommand', () => {
 
 		describe( 'restoreManualDecoratorStates()', () => {
 			it( 'synchronize values with current model state', () => {
-				setData( model, 'foo<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">u[]rl</$text>bar' );
+				setData( model, 'foo<$text linkHref="url" linkIsBar="true" linkIsFoo="true">u[]rl</$text>bar' );
 
 				expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( {
-					linkDecoratorIsFoo: true,
-					linkDecoratorIsBar: true
+					linkIsFoo: true,
+					linkIsBar: true
 				} );
 
 				command.manualDecorators.first.value = false;
 
 				expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( {
-					linkDecoratorIsFoo: false,
-					linkDecoratorIsBar: true,
+					linkIsFoo: false,
+					linkIsBar: true,
 				} );
 
 				command.restoreManualDecoratorStates();
 
 				expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( {
-					linkDecoratorIsFoo: true,
-					linkDecoratorIsBar: true,
+					linkIsFoo: true,
+					linkIsBar: true,
 				} );
 			} );
 		} );
 
 		describe( '_getDecoratorStateFromModel', () => {
 			it( 'obtain current values from the model', () => {
-				setData( model, 'foo[<$text linkDecoratorIsBar="true" linkHref="url">url</$text>]bar' );
+				setData( model, 'foo[<$text linkHref="url" linkIsBar="true">url</$text>]bar' );
 
-				expect( command._getDecoratorStateFromModel( 'linkDecoratorIsFoo' ) ).to.be.false;
-				expect( command._getDecoratorStateFromModel( 'linkDecoratorIsBar' ) ).to.be.true;
+				expect( command._getDecoratorStateFromModel( 'linkIsFoo' ) ).to.be.false;
+				expect( command._getDecoratorStateFromModel( 'linkIsBar' ) ).to.be.true;
 			} );
 		} );
 	} );

+ 3 - 3
packages/ckeditor5-link/tests/linkediting.js

@@ -482,21 +482,21 @@ describe( 'LinkEditing', () => {
 							link: {
 								addTargetToExternalLinks: false,
 								decorators: {
-									IsExternal: {
+									isExternal: {
 										mode: 'automatic',
 										callback: url => url.startsWith( 'http' ),
 										attributes: {
 											target: '_blank'
 										}
 									},
-									IsDownloadable: {
+									isDownloadable: {
 										mode: 'automatic',
 										callback: url => url.includes( 'download' ),
 										attributes: {
 											download: 'download'
 										}
 									},
-									IsMail: {
+									isMail: {
 										mode: 'automatic',
 										callback: url => url.startsWith( 'mailto:' ),
 										attributes: {

+ 5 - 5
packages/ckeditor5-link/tests/linkui.js

@@ -970,7 +970,7 @@ describe( 'LinkUI', () => {
 							plugins: [ LinkEditing, LinkUI, Paragraph ],
 							link: {
 								decorators: {
-									IsFoo: {
+									isFoo: {
 										mode: 'manual',
 										label: 'Foo',
 										attributes: {
@@ -1010,18 +1010,18 @@ describe( 'LinkUI', () => {
 				it( 'should gather information about manual decorators', () => {
 					const executeSpy = testUtils.sinon.spy( editor, 'execute' );
 
-					setModelData( model, 'f[<$text linkHref="url" linkDecoratorIsFoo="true">ooba</$text>]r' );
+					setModelData( model, 'f[<$text linkHref="url" linkIsFoo="true">ooba</$text>]r' );
 					expect( formView.urlInputView.inputView.element.value ).to.equal( 'url' );
-					expect( formView.getDecoratorSwitchesState() ).to.deep.equal( { linkDecoratorIsFoo: true } );
+					expect( formView.getDecoratorSwitchesState() ).to.deep.equal( { linkIsFoo: true } );
 
 					formView.fire( 'submit' );
 
 					expect( executeSpy.calledOnce ).to.be.true;
-					expect( executeSpy.calledWithExactly( 'link', 'url', { linkDecoratorIsFoo: true } ) ).to.be.true;
+					expect( executeSpy.calledWithExactly( 'link', 'url', { linkIsFoo: true } ) ).to.be.true;
 				} );
 
 				it( 'should reset switch state when form view is closed', () => {
-					setModelData( model, 'f[<$text linkHref="url" linkDecoratorIsFoo="true">ooba</$text>]r' );
+					setModelData( model, 'f[<$text linkHref="url" linkIsFoo="true">ooba</$text>]r' );
 
 					const manualDecorators = editor.commands.get( 'link' ).manualDecorators;
 					const firstDecoratorModel = manualDecorators.first;

+ 5 - 5
packages/ckeditor5-link/tests/manual/linkdecorator.js

@@ -22,7 +22,7 @@ ClassicEditor
 		toolbar: [ 'link', 'undo', 'redo' ],
 		link: {
 			decorators: {
-				IxExternal: {
+				isExternal: {
 					mode: 'manual',
 					label: 'Open in new window',
 					attributes: {
@@ -30,14 +30,14 @@ ClassicEditor
 						rel: 'noopener noreferrer'
 					}
 				},
-				IsDownloadable: {
+				isDownloadable: {
 					mode: 'manual',
 					label: 'Downloadable',
 					attributes: {
 						download: 'download'
 					}
 				},
-				IsGallery: {
+				isGallery: {
 					mode: 'manual',
 					label: 'Gallery link',
 					attributes: {
@@ -64,14 +64,14 @@ ClassicEditor
 		toolbar: [ 'link', 'undo', 'redo' ],
 		link: {
 			decorators: {
-				IsTelephone: {
+				isTelephone: {
 					mode: 'automatic',
 					callback: url => url.startsWith( 'tel:' ),
 					attributes: {
 						class: 'phone'
 					}
 				},
-				IsInternal: {
+				isInternal: {
 					mode: 'automatic',
 					callback: url => url.startsWith( '#' ),
 					attributes: {

+ 4 - 4
packages/ckeditor5-link/tests/unlinkcommand.js

@@ -236,14 +236,14 @@ describe( 'UnlinkCommand', () => {
 				extraPlugins: [ LinkEditing ],
 				link: {
 					decorators: {
-						IsFoo: {
+						isFoo: {
 							mode: 'manual',
 							label: 'Foo',
 							attributes: {
 								class: 'foo'
 							}
 						},
-						IsBar: {
+						isBar: {
 							mode: 'manual',
 							label: 'Bar',
 							attributes: {
@@ -261,7 +261,7 @@ describe( 'UnlinkCommand', () => {
 
 					model.schema.extend( '$text', {
 						allowIn: '$root',
-						allowAttributes: [ 'linkHref', 'linkDecoratorIsFoo', 'linkDecoratorIsBar' ]
+						allowAttributes: [ 'linkHref', 'linkIsFoo', 'linkIsBar' ]
 					} );
 
 					model.schema.register( 'p', { inheritAllFrom: '$block' } );
@@ -273,7 +273,7 @@ describe( 'UnlinkCommand', () => {
 		} );
 
 		it( 'should remove manual decorators from links together with linkHref', () => {
-			setData( model, '<$text linkHref="url" linkDecoratorIsFoo="true" linkDecoratorIsBar="true" >f[]oobar</$text>' );
+			setData( model, '<$text linkIsFoo="true" linkIsBar="true" linkHref="url">f[]oobar</$text>' );
 
 			command.execute();