2022-12-28 03:38:57 +09:00
|
|
|
import {
|
|
|
|
Node,
|
|
|
|
mergeAttributes,
|
|
|
|
nodeInputRule,
|
|
|
|
} from '@tiptap/core'
|
|
|
|
|
2022-12-28 04:13:50 +09:00
|
|
|
export const Emoji = Node.create({
|
|
|
|
name: 'em-emoji',
|
2022-12-28 03:38:57 +09:00
|
|
|
|
2022-12-28 04:13:50 +09:00
|
|
|
inline: () => true,
|
|
|
|
group: () => 'inline',
|
|
|
|
draggable: false,
|
2022-12-28 03:38:57 +09:00
|
|
|
|
2022-12-28 04:13:50 +09:00
|
|
|
parseHTML() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
tag: 'em-emoji[native]',
|
|
|
|
},
|
|
|
|
]
|
2022-12-28 03:38:57 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
addAttributes() {
|
|
|
|
return {
|
2022-12-28 04:13:50 +09:00
|
|
|
native: {
|
2022-12-28 03:38:57 +09:00
|
|
|
default: null,
|
|
|
|
},
|
2022-12-28 05:42:58 +09:00
|
|
|
fallback: {
|
|
|
|
default: null,
|
|
|
|
},
|
2022-12-28 03:38:57 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-12-28 04:13:50 +09:00
|
|
|
renderHTML(args) {
|
|
|
|
return ['em-emoji', mergeAttributes(this.options.HTMLAttributes, args.HTMLAttributes)]
|
2022-12-28 03:38:57 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
addCommands() {
|
|
|
|
return {
|
2022-12-28 04:13:50 +09:00
|
|
|
insertEmoji: name => ({ commands }) => {
|
2022-12-28 03:38:57 +09:00
|
|
|
return commands.insertContent({
|
|
|
|
type: this.name,
|
2022-12-28 04:13:50 +09:00
|
|
|
attrs: {
|
|
|
|
native: name,
|
2022-12-28 05:42:58 +09:00
|
|
|
fallback: name,
|
2022-12-28 04:13:50 +09:00
|
|
|
},
|
2022-12-28 03:38:57 +09:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addInputRules() {
|
|
|
|
return [
|
|
|
|
nodeInputRule({
|
2022-12-28 04:13:50 +09:00
|
|
|
find: EMOJI_REGEX,
|
2022-12-28 03:38:57 +09:00
|
|
|
type: this.type,
|
|
|
|
getAttributes: (match) => {
|
2022-12-28 04:13:50 +09:00
|
|
|
const [native] = match
|
2022-12-28 05:42:58 +09:00
|
|
|
return {
|
|
|
|
native,
|
|
|
|
fallback: native,
|
|
|
|
}
|
2022-12-28 03:38:57 +09:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
},
|
|
|
|
})
|