add command for mentions
This commit is contained in:
16
packages/tiptap-commands/src/commands/setInlineBlockType.js
Normal file
16
packages/tiptap-commands/src/commands/setInlineBlockType.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export default function (type, attrs = {}) {
|
||||
return (state, dispatch) => {
|
||||
const { $from } = state.selection
|
||||
const index = $from.index()
|
||||
|
||||
if (!$from.parent.canReplaceWith(index, index, type)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (dispatch) {
|
||||
dispatch(state.tr.replaceSelectionWith(type.create(attrs)))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import {
|
||||
|
||||
import markInputRule from './commands/markInputRule'
|
||||
import removeMark from './commands/removeMark'
|
||||
import setInlineBlockType from './commands/setInlineBlockType'
|
||||
import splitToDefaultListItem from './commands/splitToDefaultListItem'
|
||||
import toggleBlockType from './commands/toggleBlockType'
|
||||
import toggleList from './commands/toggleList'
|
||||
@@ -86,6 +87,7 @@ export {
|
||||
// custom
|
||||
markInputRule,
|
||||
removeMark,
|
||||
setInlineBlockType,
|
||||
splitToDefaultListItem,
|
||||
toggleBlockType,
|
||||
toggleList,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Node } from 'tiptap'
|
||||
import { setInlineBlockType } from 'tiptap-commands'
|
||||
import { triggerCharacter, suggestionsPlugin } from '../plugins/suggestions'
|
||||
|
||||
export default class MentionNode extends Node {
|
||||
@@ -41,6 +42,10 @@ export default class MentionNode extends Node {
|
||||
}
|
||||
}
|
||||
|
||||
command({ type, attrs }) {
|
||||
return setInlineBlockType(type, attrs)
|
||||
}
|
||||
|
||||
get plugins() {
|
||||
return [
|
||||
suggestionsPlugin({
|
||||
|
||||
Reference in New Issue
Block a user