From ba0d3791010003e72b0c266c0450cac2af7ffc0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 20 Jan 2021 09:23:44 +0100 Subject: [PATCH 1/3] add editor to suggestion command props --- packages/extension-mention/src/mention.ts | 16 ++++++++-------- packages/suggestion/src/suggestion.ts | 12 ++++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/extension-mention/src/mention.ts b/packages/extension-mention/src/mention.ts index a7412c2c..c5e2cd94 100644 --- a/packages/extension-mention/src/mention.ts +++ b/packages/extension-mention/src/mention.ts @@ -15,6 +15,14 @@ export const Mention = Node.create({ HTMLAttributes: {}, suggestionOptions: { char: '@', + command: ({ editor, range, attributes }) => { + editor + .chain() + .focus() + .replace(range, 'mention', attributes) + .insertText(' ') + .run() + }, }, }, @@ -69,14 +77,6 @@ export const Mention = Node.create({ Suggestion({ editor: this.editor, ...this.options.suggestionOptions, - command: ({ range, attributes }) => { - this.editor - .chain() - .focus() - .replace(range, 'mention', attributes) - .insertText(' ') - .run() - }, }), ] }, diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index 685bf898..c9120139 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -9,7 +9,11 @@ export interface SuggestionOptions { allowSpaces?: boolean, startOfLine?: boolean, suggestionClass?: string, - command?: (props: { range: Range, attributes: AnyObject }) => void, + command?: (props: { + editor: Editor, + range: Range, + attributes: AnyObject + }) => void, items?: (query: string) => any[], render?: () => { onStart?: (props: SuggestionProps) => void, @@ -83,7 +87,11 @@ export function Suggestion({ ? await items(state.query) : [], command: attributes => { - command({ range: state.range, attributes }) + command({ + editor, + range: state.range, + attributes, + }) }, decorationNode, // virtual node for popper.js or tippy.js From eb3799d0d4758262f610f859e282868a5a6c90aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 20 Jan 2021 09:23:50 +0100 Subject: [PATCH 2/3] whitespace --- docs/src/demos/Nodes/Mention/MentionList.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/demos/Nodes/Mention/MentionList.vue b/docs/src/demos/Nodes/Mention/MentionList.vue index c48104fd..ff08520e 100644 --- a/docs/src/demos/Nodes/Mention/MentionList.vue +++ b/docs/src/demos/Nodes/Mention/MentionList.vue @@ -94,6 +94,7 @@ export default { 0px 10px 20px rgba(0, 0, 0, 0.1), ; } + .item { display: block; width: 100%; From 8f95eb6aed5b18ff44fb60893041f34591d463d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 20 Jan 2021 10:47:31 +0100 Subject: [PATCH 3/3] add decorationTag and decorationClass option --- packages/suggestion/src/suggestion.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index c9120139..4a04b524 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -8,7 +8,8 @@ export interface SuggestionOptions { char?: string, allowSpaces?: boolean, startOfLine?: boolean, - suggestionClass?: string, + decorationTag?: string, + decorationClass?: string, command?: (props: { editor: Editor, range: Range, @@ -45,7 +46,8 @@ export function Suggestion({ char = '@', allowSpaces = false, startOfLine = false, - suggestionClass = 'suggestion', + decorationTag = 'span', + decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), @@ -194,8 +196,8 @@ export function Suggestion({ return DecorationSet.create(state.doc, [ Decoration.inline(range.from, range.to, { - nodeName: 'span', - class: suggestionClass, + nodeName: decorationTag, + class: decorationClass, 'data-decoration-id': decorationId, }), ])