From f40ac044ffdec3b5c8c6f749940f7b950a286c12 Mon Sep 17 00:00:00 2001 From: Beeant Date: Mon, 21 Oct 2024 06:14:00 +0000 Subject: [PATCH 1/3] feat: store mention key --- .changeset/store-mention-key.md | 5 +++++ packages/mention/src/lib/BaseMentionPlugin.ts | 5 +++-- packages/mention/src/lib/getMentionOnSelectItem.ts | 2 +- packages/mention/src/lib/types.ts | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/store-mention-key.md diff --git a/.changeset/store-mention-key.md b/.changeset/store-mention-key.md new file mode 100644 index 0000000000..2a9f0d00be --- /dev/null +++ b/.changeset/store-mention-key.md @@ -0,0 +1,5 @@ +--- +"@udecode/plate-mention": feat +--- + +store mention key \ No newline at end of file diff --git a/packages/mention/src/lib/BaseMentionPlugin.ts b/packages/mention/src/lib/BaseMentionPlugin.ts index c89e93a662..fd8d3e30a2 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..c16b7c4963 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; } From 477e218da8a62eb7de17da084e49632ee43047a6 Mon Sep 17 00:00:00 2001 From: Beeant Date: Tue, 5 Nov 2024 12:45:28 +0800 Subject: [PATCH 2/3] Update store-mention-key.md --- .changeset/store-mention-key.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/store-mention-key.md b/.changeset/store-mention-key.md index 2a9f0d00be..024105550b 100644 --- a/.changeset/store-mention-key.md +++ b/.changeset/store-mention-key.md @@ -1,5 +1,5 @@ --- -"@udecode/plate-mention": feat +"@udecode/plate-mention": patch --- -store mention key \ No newline at end of file +store mention key From 7c51ad810df70d31e50e2d545b4d09f9194ff99d Mon Sep 17 00:00:00 2001 From: Beeant Date: Tue, 5 Nov 2024 14:30:16 +0000 Subject: [PATCH 3/3] fix: optional key --- packages/mention/src/lib/BaseMentionPlugin.ts | 2 +- packages/mention/src/lib/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mention/src/lib/BaseMentionPlugin.ts b/packages/mention/src/lib/BaseMentionPlugin.ts index fd8d3e30a2..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: { key: any; search: string; value: any; }) => void; + mention: (options: { key?: any; search: string; value: any; }) => void; }; } >; diff --git a/packages/mention/src/lib/types.ts b/packages/mention/src/lib/types.ts index c16b7c4963..28c93100d4 100644 --- a/packages/mention/src/lib/types.ts +++ b/packages/mention/src/lib/types.ts @@ -1,7 +1,7 @@ import type { TElement } from '@udecode/plate-common'; export interface TMentionItemBase { - key: any; + key?: any; text: string; }