Skip to content

Commit

Permalink
Merge pull request #3649 from xbeeant/main
Browse files Browse the repository at this point in the history
feat: store mention key
  • Loading branch information
zbeyens authored Nov 5, 2024
2 parents 5d797fc + 7c51ad8 commit 7c7b4ce
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/store-mention-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-mention": patch
---

store mention key
5 changes: 3 additions & 2 deletions packages/mention/src/lib/BaseMentionPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
>;
Expand All @@ -45,9 +45,10 @@ export const BaseMentionPlugin = createSlatePlugin({
plugins: [BaseMentionInputPlugin],
}).extendEditorTransforms<MentionConfig['transforms']>(({ editor, type }) => ({
insert: {
mention: ({ value }) => {
mention: ({ key, value }) => {
insertNodes<TMentionElement>(editor, {
children: [{ text: '' }],
key,
type,
value,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/mention/src/lib/getMentionOnSelectItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
1 change: 1 addition & 0 deletions packages/mention/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TElement } from '@udecode/plate-common';

export interface TMentionItemBase {
key?: any;
text: string;
}

Expand Down

0 comments on commit 7c7b4ce

Please sign in to comment.