mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
refactoring
This commit is contained in:
parent
19c3599605
commit
008fd9b519
@ -31,6 +31,7 @@ export default {
|
|||||||
Paragraph,
|
Paragraph,
|
||||||
Text,
|
Text,
|
||||||
Mention.configure({
|
Mention.configure({
|
||||||
|
suggestionOptions: {
|
||||||
items: query => {
|
items: query => {
|
||||||
return ['Hans', 'Philipp', 'Kris'].filter(item => item.startsWith(query))
|
return ['Hans', 'Philipp', 'Kris'].filter(item => item.startsWith(query))
|
||||||
},
|
},
|
||||||
@ -71,6 +72,7 @@ export default {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
content: `
|
content: `
|
||||||
|
@ -1,14 +1,22 @@
|
|||||||
import { Node } from '@tiptap/core'
|
import { Node } from '@tiptap/core'
|
||||||
import Suggestion, { SuggestionOptions } from '@tiptap/suggestion'
|
import Suggestion, { SuggestionOptions } from '@tiptap/suggestion'
|
||||||
|
|
||||||
export type MentionOptions = Omit<SuggestionOptions, 'editor'>
|
export type MentionOptions = {
|
||||||
|
HTMLAttributes: {
|
||||||
|
[key: string]: any,
|
||||||
|
},
|
||||||
|
suggestionOptions: Omit<SuggestionOptions, 'editor'>,
|
||||||
|
}
|
||||||
|
|
||||||
export const Mention = Node.create({
|
export const Mention = Node.create({
|
||||||
name: 'mention',
|
name: 'mention',
|
||||||
|
|
||||||
defaultOptions: <MentionOptions>{
|
defaultOptions: <MentionOptions>{
|
||||||
|
HTMLAttributes: {},
|
||||||
|
suggestionOptions: {
|
||||||
char: '@',
|
char: '@',
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
|
||||||
group: 'inline',
|
group: 'inline',
|
||||||
|
|
||||||
@ -27,6 +35,15 @@ export const Mention = Node.create({
|
|||||||
id: element.getAttribute('data-mention'),
|
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 [
|
return [
|
||||||
Suggestion({
|
Suggestion({
|
||||||
editor: this.editor,
|
editor: this.editor,
|
||||||
...this.options,
|
...this.options.suggestionOptions,
|
||||||
command: ({ range, attributes }) => {
|
command: ({ range, attributes }) => {
|
||||||
this.editor
|
this.editor
|
||||||
.chain()
|
.chain()
|
||||||
|
Loading…
Reference in New Issue
Block a user