add command to suggestions
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Node } from 'tiptap'
|
||||
import { setInlineBlockType } from 'tiptap-commands'
|
||||
import { replaceText } from 'tiptap-commands'
|
||||
import { triggerCharacter, suggestionsPlugin } from '../plugins/suggestions'
|
||||
|
||||
export default class MentionNode extends Node {
|
||||
@@ -42,10 +42,6 @@ export default class MentionNode extends Node {
|
||||
}
|
||||
}
|
||||
|
||||
command({ type, attrs }) {
|
||||
return setInlineBlockType(type, attrs)
|
||||
}
|
||||
|
||||
get plugins() {
|
||||
return [
|
||||
suggestionsPlugin({
|
||||
@@ -54,6 +50,9 @@ export default class MentionNode extends Node {
|
||||
allowSpaces: true,
|
||||
startOfLine: false,
|
||||
}),
|
||||
command: ({ pos, attrs, schema }) => {
|
||||
return replaceText(pos, schema.nodes.mention, attrs)
|
||||
},
|
||||
items: this.options.items,
|
||||
onEnter: this.options.onEnter,
|
||||
onChange: this.options.onChange,
|
||||
|
||||
@@ -67,6 +67,7 @@ export function triggerCharacter(char, { allowSpaces = false, startOfLine = fals
|
||||
export function suggestionsPlugin({
|
||||
matcher = triggerCharacter('#'),
|
||||
suggestionClass = 'ProseMirror-suggestion',
|
||||
command = () => false,
|
||||
items = [],
|
||||
onEnter = () => false,
|
||||
onChange = () => false,
|
||||
@@ -129,6 +130,13 @@ export function suggestionsPlugin({
|
||||
text: next.fullText,
|
||||
decorationNode,
|
||||
items: onFilter(items, next.text),
|
||||
command: ({ pos, attrs }) => {
|
||||
command({
|
||||
pos,
|
||||
attrs,
|
||||
schema: view.state.schema,
|
||||
})(view.state, view.dispatch, view)
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
@@ -209,11 +217,11 @@ export function suggestionsPlugin({
|
||||
* @returns {boolean}
|
||||
*/
|
||||
handleKeyDown(view, event) {
|
||||
const { active } = this.getState(view.state)
|
||||
const { active, range } = this.getState(view.state)
|
||||
|
||||
if (!active) return false
|
||||
|
||||
return onKeyDown({ view, event })
|
||||
return onKeyDown({ view, event, range })
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user