mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 23:15:15 +08:00
Merge branch 'feature/allow-option-for-suggestions' into feature/remove-inferred-commands
This commit is contained in:
commit
c5d6b19d1b
@ -23,6 +23,12 @@ export const Mention = Node.create({
|
||||
.insertText(' ')
|
||||
.run()
|
||||
},
|
||||
allow: ({ editor, range }) => {
|
||||
// TODO: circular type. everthing explodes :—(
|
||||
return (editor as any)
|
||||
.can()
|
||||
.replaceRange(range, 'mention')
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -22,6 +22,10 @@ export interface SuggestionOptions {
|
||||
onExit?: (props: SuggestionProps) => void,
|
||||
onKeyDown?: (props: SuggestionKeyDownProps) => boolean,
|
||||
},
|
||||
allow?: (props: {
|
||||
editor: Editor,
|
||||
range: Range,
|
||||
}) => boolean,
|
||||
}
|
||||
|
||||
export interface SuggestionProps {
|
||||
@ -51,6 +55,7 @@ export function Suggestion({
|
||||
command = () => null,
|
||||
items = () => [],
|
||||
render = () => ({}),
|
||||
allow = () => true,
|
||||
}: SuggestionOptions) {
|
||||
|
||||
const renderer = render?.()
|
||||
@ -149,7 +154,7 @@ export function Suggestion({
|
||||
const decorationId = `id_${Math.floor(Math.random() * 0xFFFFFFFF)}`
|
||||
|
||||
// If we found a match, update the current state to show it
|
||||
if (match) {
|
||||
if (match && allow({ editor, range: match.range })) {
|
||||
next.active = true
|
||||
next.decorationId = prev.decorationId ? prev.decorationId : decorationId
|
||||
next.range = match.range
|
||||
|
Loading…
Reference in New Issue
Block a user