From ef65192710aff96872d6f7f7e6b6e7fbc80a734b Mon Sep 17 00:00:00 2001 From: Arkadiusz Filipczak Date: Mon, 4 Sep 2023 13:48:47 +0200 Subject: [PATCH 1/4] Fixes usage of MentionAttribute. --- packages/ckeditor5-mention/src/mention.ts | 27 ++++++++++++++++--- .../ckeditor5-mention/src/mentioncommand.ts | 8 ++++-- .../ckeditor5-mention/src/mentionediting.ts | 6 ++--- .../src/ui/domwrapperview.ts | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/packages/ckeditor5-mention/src/mention.ts b/packages/ckeditor5-mention/src/mention.ts index 07f3d3f58f1..53bbf921ac1 100644 --- a/packages/ckeditor5-mention/src/mention.ts +++ b/packages/ckeditor5-mention/src/mention.ts @@ -35,7 +35,28 @@ export default class Mention extends Plugin { * @param viewElement * @param data Additional data to be stored in the mention attribute. */ - public toMentionAttribute( viewElement: Element, data?: MentionAttribute ): MentionAttribute | undefined { + public toMentionAttribute( + viewElement: Element, + data: MentionData + ): ( MentionAttribute & MentionData ) | undefined; + + /** + * Creates a mention attribute value from the provided view element and optional data. + * + * ```ts + * editor.plugins.get( 'Mention' ).toMentionAttribute( viewElement ); + * + * // For a view element: @John Doe + * // it will return: + * // { id: '@joe', uid: '7a7bc7...', _text: '@John Doe' } + * ``` + * + * @param viewElement + * @param data Additional data to be stored in the mention attribute. + */ + public toMentionAttribute( viewElement: Element ): MentionAttribute | undefined; + + public toMentionAttribute( viewElement: Element, data?: object ): MentionAttribute | undefined { return _toMentionAttribute( viewElement, data ); } @@ -71,7 +92,7 @@ export type MentionAttribute = { * 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()}. */ - uid?: string; + uid: string; /** * Helper property that stores the text of the inserted mention. Used for detecting a broken mention @@ -79,5 +100,5 @@ export type MentionAttribute = { * * @internal */ - _text?: string; + _text: string; }; diff --git a/packages/ckeditor5-mention/src/mentioncommand.ts b/packages/ckeditor5-mention/src/mentioncommand.ts index b3bcf2e4db5..83563c19f09 100644 --- a/packages/ckeditor5-mention/src/mentioncommand.ts +++ b/packages/ckeditor5-mention/src/mentioncommand.ts @@ -12,7 +12,6 @@ import type { Range } from 'ckeditor5/src/engine'; import { CKEditorError, toMap } from 'ckeditor5/src/utils'; import { _addMentionAttributes } from './mentionediting'; -import type { MentionAttribute } from './mention'; /** * The mention command. @@ -84,7 +83,12 @@ export default class MentionCommand extends Command { * Note that the replaced range might be shorter than the inserted text with the mention attribute. * @fires execute */ - public override execute( options: { mention: string | MentionAttribute; marker: string; text?: string; range?: Range } ): void { + public override execute( options: { + mention: string | { id: string; [ key: string ]: unknown }; + marker: string; + text?: string; + range?: Range; + } ): void { const model = this.editor.model; const document = model.document; const selection = document.selection; diff --git a/packages/ckeditor5-mention/src/mentionediting.ts b/packages/ckeditor5-mention/src/mentionediting.ts index 03e602dc538..eec380232c1 100644 --- a/packages/ckeditor5-mention/src/mentionediting.ts +++ b/packages/ckeditor5-mention/src/mentionediting.ts @@ -84,8 +84,8 @@ export default class MentionEditing extends Plugin { * @internal */ export function _addMentionAttributes( - baseMentionData: MentionAttribute, - data?: MentionAttribute + baseMentionData: { id: string; _text: string }, + data?: object ): MentionAttribute { return Object.assign( { uid: uid() }, baseMentionData, data || {} ); } @@ -100,7 +100,7 @@ export function _addMentionAttributes( */ export function _toMentionAttribute( viewElementOrMention: Element, - data?: MentionAttribute + data?: object ): MentionAttribute | undefined { const dataMention = viewElementOrMention.getAttribute( 'data-mention' ) as string; diff --git a/packages/ckeditor5-mention/src/ui/domwrapperview.ts b/packages/ckeditor5-mention/src/ui/domwrapperview.ts index a21ab1446a4..f6bcd392792 100644 --- a/packages/ckeditor5-mention/src/ui/domwrapperview.ts +++ b/packages/ckeditor5-mention/src/ui/domwrapperview.ts @@ -7,7 +7,7 @@ * @module mention/ui/domwrapperview */ -import { View, type Template } from 'ckeditor5/src/ui'; +import { View } from 'ckeditor5/src/ui'; import type { Locale } from 'ckeditor5/src/utils'; /** From 4b680f16c0baf7630f719cca5338662bc04d43b3 Mon Sep 17 00:00:00 2001 From: Arkadiusz Filipczak Date: Tue, 5 Sep 2023 09:07:38 +0200 Subject: [PATCH 2/4] Fix usage of MentionAttribute - change object to Record. --- packages/ckeditor5-mention/src/mention.ts | 4 ++-- packages/ckeditor5-mention/src/mentionediting.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ckeditor5-mention/src/mention.ts b/packages/ckeditor5-mention/src/mention.ts index 53bbf921ac1..37794df955d 100644 --- a/packages/ckeditor5-mention/src/mention.ts +++ b/packages/ckeditor5-mention/src/mention.ts @@ -35,7 +35,7 @@ export default class Mention extends Plugin { * @param viewElement * @param data Additional data to be stored in the mention attribute. */ - public toMentionAttribute( + public toMentionAttribute>( viewElement: Element, data: MentionData ): ( MentionAttribute & MentionData ) | undefined; @@ -56,7 +56,7 @@ export default class Mention extends Plugin { */ public toMentionAttribute( viewElement: Element ): MentionAttribute | undefined; - public toMentionAttribute( viewElement: Element, data?: object ): MentionAttribute | undefined { + public toMentionAttribute( viewElement: Element, data?: Record ): MentionAttribute | undefined { return _toMentionAttribute( viewElement, data ); } diff --git a/packages/ckeditor5-mention/src/mentionediting.ts b/packages/ckeditor5-mention/src/mentionediting.ts index eec380232c1..f5cc56a959c 100644 --- a/packages/ckeditor5-mention/src/mentionediting.ts +++ b/packages/ckeditor5-mention/src/mentionediting.ts @@ -85,7 +85,7 @@ export default class MentionEditing extends Plugin { */ export function _addMentionAttributes( baseMentionData: { id: string; _text: string }, - data?: object + data?: Record ): MentionAttribute { return Object.assign( { uid: uid() }, baseMentionData, data || {} ); } @@ -100,7 +100,7 @@ export function _addMentionAttributes( */ export function _toMentionAttribute( viewElementOrMention: Element, - data?: object + data?: Record ): MentionAttribute | undefined { const dataMention = viewElementOrMention.getAttribute( 'data-mention' ) as string; From 55b08cb5c7181f3ac2804da5618f920fa8a2ac2e Mon Sep 17 00:00:00 2001 From: Arkadiusz Filipczak Date: Tue, 5 Sep 2023 10:28:54 +0200 Subject: [PATCH 3/4] Fix usage of MentionAttribute - fix doclets. --- packages/ckeditor5-mention/src/mention.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/ckeditor5-mention/src/mention.ts b/packages/ckeditor5-mention/src/mention.ts index 37794df955d..a697a10fcba 100644 --- a/packages/ckeditor5-mention/src/mention.ts +++ b/packages/ckeditor5-mention/src/mention.ts @@ -32,7 +32,6 @@ export default class Mention extends Plugin { * // { id: '@joe', userId: '1234', uid: '7a7bc7...', _text: '@John Doe' } * ``` * - * @param viewElement * @param data Additional data to be stored in the mention attribute. */ public toMentionAttribute>( @@ -50,9 +49,6 @@ export default class Mention extends Plugin { * // it will return: * // { id: '@joe', uid: '7a7bc7...', _text: '@John Doe' } * ``` - * - * @param viewElement - * @param data Additional data to be stored in the mention attribute. */ public toMentionAttribute( viewElement: Element ): MentionAttribute | undefined; From 381867d092c4d9a71f388799adc2c3883c5f5072 Mon Sep 17 00:00:00 2001 From: Arkadiusz Filipczak Date: Wed, 6 Sep 2023 09:02:22 +0200 Subject: [PATCH 4/4] Fix usage of MentionAttribute - fix doclets. --- packages/ckeditor5-mention/src/mention.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-mention/src/mention.ts b/packages/ckeditor5-mention/src/mention.ts index a697a10fcba..b8d3ab13260 100644 --- a/packages/ckeditor5-mention/src/mention.ts +++ b/packages/ckeditor5-mention/src/mention.ts @@ -22,7 +22,7 @@ import '../theme/mention.css'; */ export default class Mention extends Plugin { /** - * Creates a mention attribute value from the provided view element and optional data. + * Creates a mention attribute value from the provided view element and additional data. * * ```ts * editor.plugins.get( 'Mention' ).toMentionAttribute( viewElement, { userId: '1234' } ); @@ -40,7 +40,7 @@ export default class Mention extends Plugin { ): ( MentionAttribute & MentionData ) | undefined; /** - * Creates a mention attribute value from the provided view element and optional data. + * Creates a mention attribute value from the provided view element. * * ```ts * editor.plugins.get( 'Mention' ).toMentionAttribute( viewElement );