diff --git a/.changeset/store-mention-key.md b/.changeset/store-mention-key.md new file mode 100644 index 0000000000..024105550b --- /dev/null +++ b/.changeset/store-mention-key.md @@ -0,0 +1,5 @@ +--- +"@udecode/plate-mention": patch +--- + +store mention key diff --git a/packages/mention/src/lib/BaseMentionPlugin.ts b/packages/mention/src/lib/BaseMentionPlugin.ts index c89e93a662..494f10832e 100644 --- a/packages/mention/src/lib/BaseMentionPlugin.ts +++ b/packages/mention/src/lib/BaseMentionPlugin.ts @@ -18,7 +18,7 @@ export type MentionConfig = PluginConfig< {}, { insert: { - mention: (options: { search: string; value: any }) => void; + mention: (options: { key?: any; search: string; value: any; }) => void; }; } >; @@ -45,9 +45,10 @@ export const BaseMentionPlugin = createSlatePlugin({ plugins: [BaseMentionInputPlugin], }).extendEditorTransforms(({ editor, type }) => ({ insert: { - mention: ({ value }) => { + mention: ({ key, value }) => { insertNodes(editor, { children: [{ text: '' }], + key, type, value, }); diff --git a/packages/mention/src/lib/getMentionOnSelectItem.ts b/packages/mention/src/lib/getMentionOnSelectItem.ts index a3de2664c8..cbaa9346b8 100644 --- a/packages/mention/src/lib/getMentionOnSelectItem.ts +++ b/packages/mention/src/lib/getMentionOnSelectItem.ts @@ -25,7 +25,7 @@ export const getMentionOnSelectItem = }); const { insertSpaceAfterMention } = getOptions(); - tf.insert.mention({ search, value: item.text }); + tf.insert.mention({ key: item.key, search, value: item.text }); // move the selection after the element moveSelection(editor, { unit: 'offset' }); diff --git a/packages/mention/src/lib/types.ts b/packages/mention/src/lib/types.ts index 6859ad6d02..28c93100d4 100644 --- a/packages/mention/src/lib/types.ts +++ b/packages/mention/src/lib/types.ts @@ -1,6 +1,7 @@ import type { TElement } from '@udecode/plate-common'; export interface TMentionItemBase { + key?: any; text: string; }