Skip to content

Commit 9b60939

Browse files
committed
feat: add onTrigger for Mention
1 parent 522a87f commit 9b60939

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@coze-editor/react-components",
5+
"comment": "add onTrigger for Mention",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@coze-editor/react-components",
10+
"email": "[email protected]"
11+
}

packages/text-editor/react-components/src/mention/extension.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function mention(options: MentionOptions): Extension {
4040
},
4141
update(value, tr) {
4242
const options = tr.startState.facet(mentionConfig);
43-
const { search = true, onOpenChange, onSearch } = options;
43+
const { search = true, onOpenChange, onSearch, onTrigger } = options;
4444

4545
let { show } = value;
4646

@@ -65,6 +65,16 @@ function mention(options: MentionOptions): Extension {
6565
} else if (hasTrigger(options)) {
6666
triggerContext = options.trigger(tr);
6767
}
68+
69+
if (triggerContext && typeof onTrigger === 'function') {
70+
onTrigger({
71+
triggerContext: {
72+
from: triggerContext.from,
73+
to: triggerContext.to,
74+
triggerCharacter: triggerContext.triggerCharacter,
75+
},
76+
});
77+
}
6878
}
6979

7080
const isSelectUserEvent = tr.isUserEvent('select');

packages/text-editor/react-components/src/mention/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ interface MentionSearchEvent {
1515
value: string;
1616
}
1717

18+
interface MentionTriggerEvent {
19+
triggerContext: Pick<TriggerContext, 'from' | 'to' | 'triggerCharacter'>;
20+
}
21+
1822
interface SharedMentionOptions {
1923
search?:
2024
| {
@@ -28,6 +32,7 @@ interface SharedMentionOptions {
2832
| boolean;
2933
onOpenChange?: (e: MentionOpenChangeEvent) => void;
3034
onSearch?: (e: MentionSearchEvent) => void;
35+
onTrigger?: (e: MentionTriggerEvent) => void;
3136
}
3237

3338
type TriggerCharactersMentionOptions = SharedMentionOptions & {

0 commit comments

Comments
 (0)