多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0 KiB

4 weeks ago
import * as TipTapMention from '@tiptap/extension-mention'
export const Mention = TipTapMention.Mention.extend({
renderHTML({ HTMLAttributes }) {
const attributes =
typeof HTMLAttributes['data-id'] !== 'object' ? JSON.parse(HTMLAttributes['data-id']) : HTMLAttributes['data-id']
const innerText = attributes.name && attributes.name.length > 0 ? attributes.name : attributes.email
const styles =
attributes.isSameUser === true || attributes.isSameUser === 'true'
? 'bg-[#D4F7E0] text-[#17803D]'
: 'bg-brand-50 text-brand-500'
return [
'span',
{
'class': `mention font-semibold ${styles} rounded-md px-1`,
'data-type': 'mention',
'data-id': JSON.stringify(HTMLAttributes['data-id']),
},
[
'span',
{
style: 'font-weight: 800;',
},
'@',
],
innerText,
]
4 weeks ago
},
renderText({ node }) {
return `@${node.attrs.id.name || node.attrs.id.email || node.attrs.id.id}`
4 weeks ago
},
deleteTriggerWithBackspace: true,
4 weeks ago
})