add basic mention extension
This commit is contained in:
5
packages/extension-mention/src/index.ts
Normal file
5
packages/extension-mention/src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Mention } from './mention'
|
||||
|
||||
export * from './mention'
|
||||
|
||||
export default Mention
|
||||
49
packages/extension-mention/src/mention.ts
Normal file
49
packages/extension-mention/src/mention.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { Node } from '@tiptap/core'
|
||||
import Suggestion from '@tiptap/suggestion'
|
||||
|
||||
export const Mention = Node.create({
|
||||
name: 'mention',
|
||||
|
||||
group: 'inline',
|
||||
|
||||
inline: true,
|
||||
|
||||
selectable: false,
|
||||
|
||||
atom: true,
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
id: {
|
||||
default: null,
|
||||
},
|
||||
label: {
|
||||
default: null,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: 'span[data-mention]',
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ node, HTMLAttributes }) {
|
||||
return ['span', HTMLAttributes, `@${node.attrs.label}`]
|
||||
},
|
||||
|
||||
addProseMirrorPlugins() {
|
||||
return [
|
||||
Suggestion({}),
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Mention: typeof Mention,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user