Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: store mention key #3649

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": feat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 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