diff --git a/docs/src/demos/Nodes/Mention/index.vue b/docs/src/demos/Nodes/Mention/index.vue index 2596a9a9f..bdf541597 100644 --- a/docs/src/demos/Nodes/Mention/index.vue +++ b/docs/src/demos/Nodes/Mention/index.vue @@ -31,45 +31,47 @@ export default { Paragraph, Text, Mention.configure({ - items: query => { - return ['Hans', 'Philipp', 'Kris'].filter(item => item.startsWith(query)) - }, - render: () => { - let component - let popup + suggestionOptions: { + items: query => { + return ['Hans', 'Philipp', 'Kris'].filter(item => item.startsWith(query)) + }, + render: () => { + let component + let popup - return { - onStart: props => { - component = new VueRenderer(MentionList, { - parent: this, - propsData: props, - }) + return { + onStart: props => { + component = new VueRenderer(MentionList, { + parent: this, + propsData: props, + }) - popup = tippy('body', { - getReferenceClientRect: () => props.clientRect, - appendTo: () => document.body, - content: component.element, - showOnCreate: true, - interactive: true, - trigger: 'manual', - placement: 'top-start', - }) - }, - onUpdate(props) { - component.updateProps(props) + popup = tippy('body', { + getReferenceClientRect: () => props.clientRect, + appendTo: () => document.body, + content: component.element, + showOnCreate: true, + interactive: true, + trigger: 'manual', + placement: 'top-start', + }) + }, + onUpdate(props) { + component.updateProps(props) - popup[0].setProps({ - getReferenceClientRect: () => props.clientRect, - }) - }, - onKeyDown(props) { - return component.vm.onKeyDown(props) - }, - onExit() { - popup[0].destroy() - component.destroy() - }, - } + popup[0].setProps({ + getReferenceClientRect: () => props.clientRect, + }) + }, + onKeyDown(props) { + return component.vm.onKeyDown(props) + }, + onExit() { + popup[0].destroy() + component.destroy() + }, + } + }, }, }), ], diff --git a/packages/extension-mention/src/mention.ts b/packages/extension-mention/src/mention.ts index cae92f99c..17e66e28c 100644 --- a/packages/extension-mention/src/mention.ts +++ b/packages/extension-mention/src/mention.ts @@ -1,13 +1,21 @@ import { Node } from '@tiptap/core' import Suggestion, { SuggestionOptions } from '@tiptap/suggestion' -export type MentionOptions = Omit +export type MentionOptions = { + HTMLAttributes: { + [key: string]: any, + }, + suggestionOptions: Omit, +} export const Mention = Node.create({ name: 'mention', defaultOptions: { - char: '@', + HTMLAttributes: {}, + suggestionOptions: { + char: '@', + }, }, group: 'inline', @@ -27,6 +35,15 @@ export const Mention = Node.create({ id: element.getAttribute('data-mention'), } }, + renderHTML: attributes => { + if (!attributes.id) { + return {} + } + + return { + 'data-mention': attributes.id, + } + }, }, } }, @@ -47,7 +64,7 @@ export const Mention = Node.create({ return [ Suggestion({ editor: this.editor, - ...this.options, + ...this.options.suggestionOptions, command: ({ range, attributes }) => { this.editor .chain()