Merge branch 'feature/suggestions' of github.com:ueberdosis/tiptap-next into feature/suggestions

This commit is contained in:
Hans Pagel
2021-01-20 11:30:47 +01:00
3 changed files with 25 additions and 14 deletions

View File

@@ -94,6 +94,7 @@ export default {
0px 10px 20px rgba(0, 0, 0, 0.1), 0px 10px 20px rgba(0, 0, 0, 0.1),
; ;
} }
.item { .item {
display: block; display: block;
width: 100%; width: 100%;

View File

@@ -15,6 +15,14 @@ export const Mention = Node.create({
HTMLAttributes: {}, HTMLAttributes: {},
suggestionOptions: { suggestionOptions: {
char: '@', char: '@',
command: ({ editor, range, attributes }) => {
editor
.chain()
.focus()
.replace(range, 'mention', attributes)
.insertText(' ')
.run()
},
}, },
}, },
@@ -69,14 +77,6 @@ export const Mention = Node.create({
Suggestion({ Suggestion({
editor: this.editor, editor: this.editor,
...this.options.suggestionOptions, ...this.options.suggestionOptions,
command: ({ range, attributes }) => {
this.editor
.chain()
.focus()
.replace(range, 'mention', attributes)
.insertText(' ')
.run()
},
}), }),
] ]
}, },

View File

@@ -8,8 +8,13 @@ export interface SuggestionOptions {
char?: string, char?: string,
allowSpaces?: boolean, allowSpaces?: boolean,
startOfLine?: boolean, startOfLine?: boolean,
suggestionClass?: string, decorationTag?: string,
command?: (props: { range: Range, attributes: AnyObject }) => void, decorationClass?: string,
command?: (props: {
editor: Editor,
range: Range,
attributes: AnyObject
}) => void,
items?: (query: string) => any[], items?: (query: string) => any[],
render?: () => { render?: () => {
onStart?: (props: SuggestionProps) => void, onStart?: (props: SuggestionProps) => void,
@@ -41,7 +46,8 @@ export function Suggestion({
char = '@', char = '@',
allowSpaces = false, allowSpaces = false,
startOfLine = false, startOfLine = false,
suggestionClass = 'suggestion', decorationTag = 'span',
decorationClass = 'suggestion',
command = () => null, command = () => null,
items = () => [], items = () => [],
render = () => ({}), render = () => ({}),
@@ -83,7 +89,11 @@ export function Suggestion({
? await items(state.query) ? await items(state.query)
: [], : [],
command: attributes => { command: attributes => {
command({ range: state.range, attributes }) command({
editor,
range: state.range,
attributes,
})
}, },
decorationNode, decorationNode,
// virtual node for popper.js or tippy.js // virtual node for popper.js or tippy.js
@@ -186,8 +196,8 @@ export function Suggestion({
return DecorationSet.create(state.doc, [ return DecorationSet.create(state.doc, [
Decoration.inline(range.from, range.to, { Decoration.inline(range.from, range.to, {
nodeName: 'span', nodeName: decorationTag,
class: suggestionClass, class: decorationClass,
'data-decoration-id': decorationId, 'data-decoration-id': decorationId,
}), }),
]) ])