2022-07-24 03:37:34 +00:00
|
|
|
import Mention from '@tiptap/extension-mention'
|
|
|
|
import {
|
|
|
|
mergeAttributes,
|
|
|
|
NodeViewWrapper,
|
|
|
|
ReactNodeViewRenderer,
|
|
|
|
} from '@tiptap/react'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
import { Linkify } from '../linkify'
|
|
|
|
|
|
|
|
const name = 'mention-component'
|
|
|
|
|
|
|
|
const MentionComponent = (props: any) => {
|
|
|
|
return (
|
2022-08-06 20:39:52 +00:00
|
|
|
<NodeViewWrapper className={clsx(name, 'not-prose text-indigo-700')}>
|
2022-07-24 03:37:34 +00:00
|
|
|
<Linkify text={'@' + props.node.attrs.label} />
|
|
|
|
</NodeViewWrapper>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mention extension that renders React. See:
|
|
|
|
* https://tiptap.dev/guide/custom-extensions#extend-existing-extensions
|
|
|
|
* https://tiptap.dev/guide/node-views/react#render-a-react-component
|
|
|
|
*/
|
|
|
|
export const DisplayMention = Mention.extend({
|
|
|
|
parseHTML: () => [{ tag: name }],
|
|
|
|
renderHTML: ({ HTMLAttributes }) => [name, mergeAttributes(HTMLAttributes)],
|
2022-08-06 20:39:52 +00:00
|
|
|
addNodeView: () =>
|
|
|
|
ReactNodeViewRenderer(MentionComponent, { className: 'inline-block' }),
|
2022-07-24 03:37:34 +00:00
|
|
|
})
|