8
0
Просмотр исходного кода

Renamed _uid to uid as it's used in integrations.

Piotrek Koszuliński 5 лет назад
Родитель
Сommit
881e67109d

+ 1 - 1
packages/ckeditor5-mention/docs/_snippets/examples/chat-with-mentions.js

@@ -150,7 +150,7 @@ function MentionLinks( editor ) {
 				// Make mention attribute to be wrapped by other attribute elements.
 				priority: 20,
 				// Prevent merging mentions together.
-				id: modelAttributeValue._uid
+				id: modelAttributeValue.uid
 			} );
 		},
 		converterPriority: 'high'

+ 1 - 1
packages/ckeditor5-mention/docs/_snippets/features/mention-customization.js

@@ -83,7 +83,7 @@ function MentionCustomization( editor ) {
 				// Make mention attribute to be wrapped by other attribute elements.
 				priority: 20,
 				// Prevent merging mentions together.
-				id: modelAttributeValue._uid
+				id: modelAttributeValue.uid
 			} );
 		},
 		converterPriority: 'high'

+ 1 - 1
packages/ckeditor5-mention/docs/examples/chat-with-mentions.md

@@ -331,7 +331,7 @@ function MentionLinks( editor ) {
 				// Make mention attribute to be wrapped by other attribute elements.
 				priority: 20,
 				// Prevent merging mentions together.
-				id: modelAttributeValue._uid
+				id: modelAttributeValue.uid
 			} );
 		},
 		converterPriority: 'high'

+ 3 - 3
packages/ckeditor5-mention/docs/features/mentions.md

@@ -198,7 +198,7 @@ The converters must be defined with a `'high'` priority to be executed before th
 
 To control how the mention element is wrapped by other attribute elements (like bold, italic, etc) set its {@link module:engine/view/attributeelement~AttributeElement#priority}. To replicate default plugin behavior and make mention to be wrapped by other elements set priority to `20`.
 
-By default, attribute elements that are next to each other and have the same value will be rendered as single HTML element. To prevent this the model attribute value object expose a unique id of each inserted mention to the model as `_uid`. To prevent merging subsequent mentions set it as {@link module:engine/view/attributeelement~AttributeElement#id}.
+By default, attribute elements that are next to each other and have the same value will be rendered as single HTML element. To prevent this the model attribute value object expose a unique id of each inserted mention to the model as `uid`. To prevent merging subsequent mentions set it as {@link module:engine/view/attributeelement~AttributeElement#id}.
 
 **Note:** The feature prevents copying fragments of existing mentions. If only a part of a mention is selected, it will be copied as plain text. The internal converter with the {@link module:engine/conversion/conversion~ConverterDefinition `'highest'` priority} controls this behaviour; thus, we do not recommend adding mention converters with the `'highest'` priority to avoid collisions and quirky results.
 
@@ -262,7 +262,7 @@ function MentionCustomization( editor ) {
 				// Make mention attribute to be wrapped by other attribute elements.
 				priority: 20,
 				// Prevent merging mentions together.
-				id: modelAttributeValue._uid
+				id: modelAttributeValue.uid
 			} );
 		},
 		converterPriority: 'high'
@@ -354,7 +354,7 @@ function MentionCustomization( editor ) {
 				// Make mention attribute to be wrapped by other attribute elements.
 				priority: 20,
 				// Prevent merging mentions together.
-				id: modelAttributeValue._uid
+				id: modelAttributeValue.uid
 			} );
 		},
 		converterPriority: 'high'

+ 4 - 3
packages/ckeditor5-mention/src/mention.js

@@ -29,7 +29,7 @@ export default class Mention extends Plugin {
 	 *
 	 *		// For a view element: <span data-mention="@joe">@John Doe</span>
 	 *		// it will return:
-	 *		// { id: '@joe', userId: '1234', _uid: '7a7bc7...', _text: '@John Doe' }
+	 *		// { id: '@joe', userId: '1234', uid: '7a7bc7...', _text: '@John Doe' }
 	 *
 	 * @param {module:engine/view/element~Element} viewElement
 	 * @param {String|Object} [data] Additional data to be stored in the mention attribute.
@@ -225,8 +225,9 @@ export default class Mention extends Plugin {
  * See {@link module:mention/mention~Mention#toMentionAttribute `Mention#toMentionAttribute()`}.
  *
  * @interface module:mention/mention~MentionAttribute
- * @property {String} id The ID of a mention. It identifies the mention item in the mention feed.
- * @property {String} _uid An internal mention view item ID. Should be passed as an `option.id` when using
+ * @property {String} id The ID of a mention. It identifies the mention item in the mention feed. There can be multiple mentions
+ * in the document with the same ID (e.g. the same hashtag being mentioned).
+ * @property {String} uid A unique ID of this mention instance. Should be passed as an `option.id` when using
  * {@link module:engine/view/downcastwriter~DowncastWriter#createAttributeElement writer.createAttributeElement()}.
  * @property {String} _text Helper property that stores the text of the inserted mention. Used for detecting a broken mention
  * in the editing area.

+ 2 - 2
packages/ckeditor5-mention/src/mentionediting.js

@@ -69,7 +69,7 @@ export default class MentionEditing extends Plugin {
 }
 
 export function _addMentionAttributes( baseMentionData, data ) {
-	return Object.assign( { _uid: uid() }, baseMentionData, data || {} );
+	return Object.assign( { uid: uid() }, baseMentionData, data || {} );
 }
 
 /**
@@ -142,7 +142,7 @@ function createViewMentionElement( mention, viewWriter ) {
 	};
 
 	const options = {
-		id: mention._uid,
+		id: mention.uid,
 		priority: 20
 	};
 

+ 1 - 1
packages/ckeditor5-mention/tests/manual/mention-custom-view.js

@@ -52,7 +52,7 @@ class CustomMentionAttributeView extends Plugin {
 					'href': modelAttributeValue.link
 				}, {
 					priority: 20,
-					id: modelAttributeValue._uid
+					id: modelAttributeValue.uid
 				} );
 			},
 			converterPriority: 'high'

+ 2 - 2
packages/ckeditor5-mention/tests/mention.js

@@ -62,7 +62,7 @@ describe( 'Mention', () => {
 			const mentionAttribute = editor.plugins.get( 'Mention' ).toMentionAttribute( viewElement );
 
 			expect( mentionAttribute ).to.have.property( 'id', '@John' );
-			expect( mentionAttribute ).to.have.property( '_uid' );
+			expect( mentionAttribute ).to.have.property( 'uid' );
 			expect( mentionAttribute ).to.have.property( '_text', 'John Doe' );
 		} );
 
@@ -77,7 +77,7 @@ describe( 'Mention', () => {
 
 			expect( mentionAttribute ).to.have.property( 'id', '@John' );
 			expect( mentionAttribute ).to.have.property( 'foo', 'bar' );
-			expect( mentionAttribute ).to.have.property( '_uid' );
+			expect( mentionAttribute ).to.have.property( 'uid' );
 			expect( mentionAttribute ).to.have.property( '_text', 'John Doe' );
 		} );
 

+ 1 - 1
packages/ckeditor5-mention/tests/mentioncommand.js

@@ -167,7 +167,7 @@ describe( 'MentionCommand', () => {
 
 	function assertMention( textNode, id ) {
 		expect( textNode.hasAttribute( 'mention' ) ).to.be.true;
-		expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_uid' );
+		expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'uid' );
 		expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_text', textNode.data );
 		expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'id', id );
 	}

+ 9 - 9
packages/ckeditor5-mention/tests/mentionediting.js

@@ -77,7 +77,7 @@ describe( 'MentionEditing', () => {
 			expect( textNode.hasAttribute( 'mention' ) ).to.be.true;
 			expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'id', '@John' );
 			expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_text', '@John' );
-			expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_uid' );
+			expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'uid' );
 
 			const expectedView = '<p>foo <span class="mention" data-mention="@John">@John</span> bar</p>';
 
@@ -96,7 +96,7 @@ describe( 'MentionEditing', () => {
 			expect( textNode.hasAttribute( 'mention' ) ).to.be.true;
 			expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'id', '@Ted Mosby' );
 			expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_text', 'Ted Mosby' );
-			expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_uid' );
+			expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'uid' );
 
 			const expectedView = '<p>Hello <b class="mention" data-mention="@Ted Mosby">Ted Mosby</b></p>';
 
@@ -122,8 +122,8 @@ describe( 'MentionEditing', () => {
 			assertTextNode( paragraph.getChild( 0 ) );
 			assertTextNode( paragraph.getChild( 1 ) );
 
-			const firstMentionId = paragraph.getChild( 0 ).getAttribute( 'mention' )._uid;
-			const secondMentionId = paragraph.getChild( 1 ).getAttribute( 'mention' )._uid;
+			const firstMentionId = paragraph.getChild( 0 ).getAttribute( 'mention' ).uid;
+			const secondMentionId = paragraph.getChild( 1 ).getAttribute( 'mention' ).uid;
 
 			expect( firstMentionId ).to.not.equal( secondMentionId );
 
@@ -138,7 +138,7 @@ describe( 'MentionEditing', () => {
 				expect( textNode.hasAttribute( 'mention' ) ).to.be.true;
 				expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'id', '@John' );
 				expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_text', '@John' );
-				expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_uid' );
+				expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'uid' );
 			}
 		} );
 
@@ -151,7 +151,7 @@ describe( 'MentionEditing', () => {
 			expect( textNode.hasAttribute( 'mention' ) ).to.be.true;
 			expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'id', '@John' );
 			expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_text', '@Jo' );
-			expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_uid' );
+			expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'uid' );
 
 			const expectedView = '<p><span class="mention" data-mention="@John">@Jo</span></p>';
 
@@ -199,7 +199,7 @@ describe( 'MentionEditing', () => {
 						'href': modelAttributeValue.link
 					}, {
 						priority: 20,
-						id: modelAttributeValue._uid
+						id: modelAttributeValue.uid
 					} );
 				},
 				converterPriority: 'high'
@@ -315,7 +315,7 @@ describe( 'MentionEditing', () => {
 			expect( textNode.hasAttribute( 'mention' ) ).to.be.true;
 			expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'id', '@John' );
 			expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_text', '@John' );
-			expect( textNode.getAttribute( 'mention' ) ).to.have.property( '_uid' );
+			expect( textNode.getAttribute( 'mention' ) ).to.have.property( 'uid' );
 
 			model.change( writer => {
 				const paragraph = doc.getRoot().getChild( 0 );
@@ -682,7 +682,7 @@ function addCustomMentionConverters( editor ) {
 				'data-mention': modelAttributeValue.id
 			}, {
 				priority: 20,
-				id: modelAttributeValue._uid
+				id: modelAttributeValue.uid
 			} );
 		},
 		converterPriority: 'high'

+ 5 - 5
packages/ckeditor5-mention/tests/mentionui.js

@@ -621,7 +621,7 @@ describe( 'MentionUI', () => {
 						writer.createPositionAt( doc.getRoot().getChild( 0 ), 9 )
 					);
 
-					writer.setAttribute( 'mention', { id: '@Lily', _uid: 1234 }, range );
+					writer.setAttribute( 'mention', { id: '@Lily', uid: 1234 }, range );
 				} );
 
 				return waitForDebounce()
@@ -651,7 +651,7 @@ describe( 'MentionUI', () => {
 						writer.createPositionAt( doc.getRoot().getChild( 0 ), 9 )
 					);
 
-					writer.setAttribute( 'mention', { id: '@Lily', _uid: 1234 }, range );
+					writer.setAttribute( 'mention', { id: '@Lily', uid: 1234 }, range );
 				} );
 
 				return waitForDebounce()
@@ -725,7 +725,7 @@ describe( 'MentionUI', () => {
 			it( 'should not show panel when selection is after existing mention', () => {
 				setData( model, '<paragraph>foo [@Lily] bar[]</paragraph>' );
 				model.change( writer => {
-					writer.setAttribute( 'mention', { id: '@Lily', _uid: 1234 }, doc.selection.getFirstRange() );
+					writer.setAttribute( 'mention', { id: '@Lily', uid: 1234 }, doc.selection.getFirstRange() );
 				} );
 
 				return waitForDebounce()
@@ -750,7 +750,7 @@ describe( 'MentionUI', () => {
 						writer.createPositionAt( doc.getRoot().getChild( 0 ), 4 ),
 						writer.createPositionAt( doc.getRoot().getChild( 0 ), 9 )
 					);
-					writer.setAttribute( 'mention', { id: '@Lily', _uid: 1234 }, range );
+					writer.setAttribute( 'mention', { id: '@Lily', uid: 1234 }, range );
 				} );
 
 				return waitForDebounce()
@@ -1295,7 +1295,7 @@ describe( 'MentionUI', () => {
 				setData( model, '<paragraph>foo [#101] bar</paragraph><paragraph></paragraph>' );
 
 				model.change( writer => {
-					writer.setAttribute( 'mention', { id: '#101', _uid: 1234 }, doc.selection.getFirstRange() );
+					writer.setAttribute( 'mention', { id: '#101', uid: 1234 }, doc.selection.getFirstRange() );
 				} );
 
 				// Increase the response time to extend the debounce time out.